Nginx负载均衡配置文件(ip_hash策略解决session问题)

mtain 2016年04月28日 271次浏览

**Nginx版本:**nginx-1.8.1.tar.gz

配置文件:
默认放置位置/usr/local/nginx/conf/nginx.conf

user root;
worker_processes 1;

error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;

pid logs/nginx.pid;

events {
use epoll;
worker_connections 1024;
}

http {
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;
upstream localhost {  
  ip_hash;
  server 127.0.0.1:7001;
  server 127.0.0.1:7002;   
  server 127.0.0.1:7003;   
  server 127.0.0.1:7004;   
  server 127.0.0.1:7005;   
  server 127.0.0.1:7006;   
  server 127.0.0.1:7007;   
  server 127.0.0.1:7008;   
  server 127.0.0.1:7009;   
  server 127.0.0.1:7010;   
  server 127.0.0.1:7011;   
  server 127.0.0.1:7012;   
  server 127.0.0.1:7013;   
  server 127.0.0.1:7014;   
  server 127.0.0.1:7015;   
  server 127.0.0.1:7016;   
  server 127.0.0.1:7017;   
  server 127.0.0.1:7018;   
  server 127.0.0.1:7019;   
  server 127.0.0.1:7020;   
}


server {
listen 80;
server_name localhost;

  charset utf-8;
  
  #charset koi8-r;
  #access_log  logs/host.access.log  main;
  location / {
    proxy\_connect\_timeout	3;  
    proxy\_send\_timeout	30;  
    proxy\_read\_timeout	30;  
    proxy_pass http://localhost;
  }
  #error_page  404			  /404.html;
  # redirect server error pages to the static page /50x.html
  }

}

相关问题

此配置文件未对session进行配置,可能存在session丢失等问题。