Nginx 容灾设置

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.屏蔽一个服务器端口 ,查看是否可以转发

这里使用Jemeter进行测试

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值