nginx.conf配置文件内容:
#根据服务器核心数设定 worker_processes 1; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; source_charset GB2312; server_names_hash_bucket_size 256; client_header_buffer_size 256k; large_client_header_buffers 4 256k; #size limits client_max_body_size 50m; client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; sendfile on; tcp_nopush on; keepalive_timeout 120; #参数加大,以解决做代理时502错误 tcp_nodelay on; #定义一个服务器列表,weight代表权重,值越高越容易分配到. upstream webservers{ server 192.168.12.2:80 weight=1; server 192.168.12.3:80 weight=2; keepalive 100; #负载均衡点的可用检测 #nginx支持的几种算法,1,轮询 2,weight 3,ip hash 4,fair(第三方) 5,url_hash (第三方) #ip_hash为每个请求按访问ip的hash结果分配,每个访客有固定的后端服务器,可以解决session问题 ip_hash; } server { listen 80; server_name 192.168.12.1; charset GB2312; location / { #使用proxy_pass代替一般配置中的fastcgi_pass proxy_pass proxy_redirect off ; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 50m; client_body_buffer_size 256k; proxy_connect_timeout 30; proxy_send_timeout 30; proxy_read_timeout 60; proxy_buffer_size 256k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 256k; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; proxy_max_temp_file_size 128m; } } }