user www www; worker_processes 10; error_log /data1/logs/nginx_error.log crit; pid /usr/local/webserver/nginx/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; #charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; #tcp_nopush on; keepalive_timeout 65; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #允许客户端请求的最大单个文件字节数 client_max_body_size 300m; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户 client_body_buffer_size 128k; #跟后端服务器连接的超时时间_发起握手等候响应超时时间 proxy_connect_timeout 600; #连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理 proxy_read_timeout 600; #后端服务器数据回传时间_就是在规定时间内后端服务器必须传完所有的数据 proxy_send_timeout 600; #代理请求缓存区_这个缓存区间会保存用户的头信息以供Nginx进行规则处理_一般只要能保存下头信息即可 proxy_buffer_size 16k; #同上 告诉Nginx保存单个用的几个Buffer 最大用多大空间 proxy_buffers 4 32k; #如果系统很忙的时候可以申请更大的proxy_buffers 官方推荐*2 proxy_busy_buffers_size 64k; #proxy缓存临时文件的大小 proxy_temp_file_write_size 64k; upstream php_server_pool { server 192.168.1.10:80 weight=4 max_fails=2 fail_timeout=30s; server 192.168.1.11:80 weight=4 max_fails=2 fail_timeout=30s; server 192.168.1.12:80 weight=2 max_fails=2 fail_timeout=30s; } upstream message_server_pool { server 192.168.1.13:3245; server 192.168.1.14:3245 down; } upstream bbs_server_pool { server 192.168.1.15:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.1.16:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.1.17:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.1.18:80 weight=1 max_fails=2 fail_timeout=30s; } #第一个虚拟主机,反向代理php_server_pool这组服务器 server { listen 80; server_name www.yourdomain.com; location / { #如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。 proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_pass http://php_server_pool; proxy_set_header Host www.yourdomain.com; proxy_set_header X-Forwarded-For $remote_addr; } access_log /data1/logs/www.yourdomain.com_access.log; } #第二个虚拟主机 server { listen 80; server_name www1.yourdomain.com; #访问http://www1.yourdomain.com/message/***地址,反向代理message_server_pool这组服务器 location /message/ { proxy_pass http://message_server_pool; proxy_set_header Host $host; } #访问除了/message/之外的http://www1.yourdomain.com/***地址,反向代理php_server_pool这组服务器 location / { proxy_pass http://php_server_pool; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } access_log /data1/logs/message.yourdomain.com_access.log; } #第三个虚拟主机 server{ listen 80; server_name bbs.yourdomain.com *.bbs.yourdomain.com; location / { proxy_pass http://bbs_server_pool; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } access_log off; } }