userwww www;
worker_processes16;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_log/var/log/nginx.error.loginfo;
pidlogs/nginx.pid;
worker_rlimit_nofile 204800;
events {
worker_connections204800;
}
http {
includemime.types;
default_typeapplication/octet-stream;
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
#限制单位时间内一个ip请求数;
# limit_req_zone $binary_remote_addr zone=one:10m rate=1r/m;
limit_conn_zone $binary_remote_addr zone=perip:10m;
send_timeout60;
access_log /dev/null;
error_log /dev/null;
server_names_hash_bucket_size 128;
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
#client_max_body_size 8m;
tcp_nopushon;
sendfileoff;
server_tokens off;
keepalive_timeout 60;
fastcgi_intercept_errors on;
client_body_buffer_size512k;
proxy_connect_timeout300;
proxy_read_timeout300;
proxy_send_timeout300;
proxy_buffer_size256k;
proxy_buffers4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
gzipon;
gzip_min_length1k;
gzip_buffers4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_typestext/plain application/x-javascript text/css application/xml;
gzip_vary on;
# proxy_store on;
# proxy_store_access user:rw group:rw all:rw;
proxy_temp_path/tmp/proxy_temp_dir;
proxy_cache_path/tmp/proxy_cache_dirlevels=1:2keys_zone=cache_one:200m inactive=1d max_size=15g;
upstream backend_server{
server10.0.1.149:8080 weight=1 max_fails=2 fail_timeout=30s;
server10.0.1.150:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen80;
server_name10.0.0.149;
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|htm)$ {
root /staticfile2012;
index index.html index.htm;
}
location ~ ^/nginx_status
{
stub_status on;
access_log off;
allow 10.0.0.250;
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
server {
listen8080;
server_name 10.0.1.149;
root /staticfile2012;
index index.html index.htm;
location ~ /purge(/.*)
{
#设置只允许指定的IP或IP段才可以清除URL缓存。
allowall;
allow127.0.0.1;
proxy_cache_purgecache_one$host$1$is_args$args;
}
}
server {
listen80;
server_name file1.qlteacher.com;
root/staticfile2012;
index index.html index.htm;
# location ~ /purge(/.*)
# {
#设置只允许指定的IP或IP段才可以清除URL缓存。
# allowall;
# allow127.0.0.1;
# proxy_cache_purgecache_one$host$1$is_args$args;
#}
location /
{
limit_conn perip 1;
limit_rate 50K;
#一个ip单位时间内限制请求,但会导致单位时间内同局域网内多数用户不能下载503错误提示。
# limit_req zone=one burst=1;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
#对不同的HTTP状态码设置不同的缓存时间
proxy_cache_valid200 304 20s;
#以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host$host;
proxy_set_header X-Forwarded-For$remote_addr;
proxy_set_headerX-Real-IP$remote_addr;
proxy_pass http://backend_server;
expires30d;
access_logoff;
}
#不启用反向代理
# location /
#{
# limit_conn perip 1;
# limit_rate 50K;
# root/staticfile2012;
# index index.html index.htm;
# }
#location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|htm|asf|avi|fla|flv|mp3|mp4|rm|rmi|rmvb|wav|wma|wmv|7z|aiff|bmp|csv|doc|docx|gz|gzip|mid|xml|zip|mov|mpc|mepg|mpg|ods|odt|pdf|ppt|pptx|pxd|qt|ram|rar|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|xls|xlsx)$ {
#root/staticfile2012;
#index index.html index.htm;
#expires30d;
#access_logoff;
#}
}
}