Nginx 容灾设置
程序员文章站
2022-04-09 20:41:59
...
Nginx 容灾设置
Nginx安装
http://nginx.org/en/download.html
1.tar -xzvf nginx-1.10.2.tar.gz
- cd nginx-1.10.2
- ./configure --prefix=/usr/local/nginx --with-http_ssl_module (如果报错,检查安装模块的依赖)
- make && make install
- cd /usr/local/nginx
- cd sbin
./nginx -t 出现下图代表安装成功
配置文件设置
- cd /usr/local/nginx/conf
- vi nginx.conf (原配置备份)
- 配置示例
worker_processes 24;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 204800;
events {
use epoll;
multi_accept on;
worker_connections 204800;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
access_log off;
#error_log /var/log/nginx/error.log crit;
keepalive_timeout 60;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 60;
open_file_cache max=1000000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
#keepalive_timeout 65;
#gzip on;
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6].";
#websocket 需要加下这个
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream http_server_a2 {
server 192.168.xxx.xxx:8080 max_fails=1 weight=5 fail_timeout=100s;
server 192.168.xxx.xxx:8080 max_fails=1 weight=5 fail_timeout=100s;
}
server {
listen 8080;
server_name http_server_a2;
location / {
index index.html index.htm;
proxy_pass http://http_server_a2;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_403 http_404 non_idempotent;
#proxy_next_upstream_tries 1;
client_body_buffer_size 256k;
proxy_connect_timeout 10;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
关键词:proxy_next_upstream http_server_a2
测试方法:192.168.xxx.xxx 192.168.xxx.xxx 为两台服务器 都启动tomcat
1.8080端口全部放开 查看后台输出 是否有记录
2.屏蔽一个服务器端口 ,查看是否可以转发