user www www;
worker_processes 2;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 1024;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
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 65;
tcp_nodelay on;
server_names_hash_bucket_size 128;
#保存服务器名字的hash表
client_header_buffer_size 4k;
#客户端请求头部的缓冲区大小
large_client_header_buffers 4 32k;
#如果header过大,它会使用large_client_header_buffers来读取
client_max_body_size 300m;
#允许客户端请求的最大单文件字节数
client_body_buffer_size 512k;
#缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 5;
#nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 60;
#连接成功后,后端服务器响应时间(代理接收超时)
proxy_send_timeout 5;
#后端服务器数据回传时间(代理发送超时)
proxy_buffer_size 16k;
#设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 64k;
#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 128k;
#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 128k;
#设定缓存文件夹大小,大于这个值,将从upstream服务器传
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;
proxy_temp_path /usr/local/nginx/proxy_temp_dir;#proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
proxy_cache_path /usr/local/nginx/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
#设置内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB
upstream local_pool {
server 192.168.2.139:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.2.128:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.html;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://local_pool;
expires 1d;
}
location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://local_pool;
}