【老王公众号】

Nginx负载均衡配置调优

worker_processes  4;
error_log  logs/error.log crit; #日志位置和日志级别
pid  logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    worker_connections 65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream backend {
             #ip_hash;
             server 172.17.0.5:8080 weight=1 max_fails=2 fail_timeout=2;
             server 172.17.0.4:8080 weight=1 max_fails=2 fail_timeout=2;
         }
    server {

        listen       80;

        server_name  2;

 

        location / {

        #设置主机头和客户端真实地址,以便服务器获取客户端真实IP

             proxy_set_header Host $host;

             proxy_set_header X-Real-IP $remote_addr;

             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header Host  $http_host;
             proxy_set_header Cookie $http_cookie;
 
             #禁用缓存
             proxy_buffering off;

             #反向代理的地址

             proxy_pass http://backend;     
        }
    }
}

 

posted @ 2017-02-27 15:18  CTO老王  阅读(623)  评论(0编辑  收藏  举报