userwww www;javascript
worker_processes16;css
#error_loglogs/error.log;html
#error_loglogs/error.lognotice;java
#error_log/var/log/nginx.error.loginfo;nginx
pidlogs/nginx.pid;數組
worker_rlimit_nofile 204800;緩存
events {app
worker_connections204800;tcp
}ide
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;
#}
}
}