worker_processes 16;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 204800;
events
{
use epoll;
worker_connections 204800;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128; #指定服务器名称哈希表的框大小
client_header_buffer_size 32k;
large_client_header_buffers 4 128k; #以上两个是设定客户端请求的Header头缓冲区大小,对于
#cookie内容较大的请求,应增大改值。(400或414错误)
client_max_body_size 300m;#允许客户端请求的最大单文件字节数
client_body_buffer_size 512k; #缓冲区代理缓冲用户端请求的最大字节数
sendfile on;
tcp_nopush on;#以下两个选项用于防止网络阻塞
tcp_nodelay on;#开启高效文件传输模式
keepalive_timeout 120; #长链接超时时间
server_tokens off;#隐藏nginx版本信息
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
charset gb2312;
gzip on; #开启gzip模式
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
#gzip_proxied any; 前端是squid的情况下要加此参数,否则squid上不缓存gzip文件
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;
ssi on; #一下三行开启shtml支持
ssi_silent_errors on;
ssi_types text/shtml;
proxy_connect_timeout 600;#nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 600; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_send_timeout 600; #后端服务器数据回传时间(代理发送超时)
proxy_buffer_size 16k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 8 64k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置(4 32k)
proxy_busy_buffers_size 128k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 200m;#设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
proxy_ignore_client_abort on; #不允许代理端主动关闭连接
# proxy_store on; #一下三行开启proxy_store缓存
# proxy_store_access user:rw group:rw all:rw;
# proxy_temp_path /data/tempcache; #设置proxy_temp目录
# proxy_temp_path /nginx/tempcache; #设置proxy_temp内存缓存
proxy_cache_path /data/cache levels=1:2 keys_zone=cache_one:400m inactive=1d max_size=50g;#设置Web缓存区名称为cach e_one,内存缓存空间大小为400MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为50GB。
# proxy_cache_path /nginx/cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=4g;#设置内存缓存
set_real_ip_from 192.168.100.254;
real_ip_header X-Forwarded-For;
upstream webserver {
#ip_hash;
server 192.168.100.21:80 weight=3 max_fails=2 fail_timeout=10s;
server 192.168.100.22:80 weight=3 max_fails=2 fail_timeout=10s;
server 192.168.100.20:81 weight=1 max_fails=2 fail_timeout=10s;
server 127.0.0.1:81 weight=1 max_fails=2 fail_timeout=10s;
}
server {
listen 80;
server_name xxxxx;
index index.shtml index.html index.htm index.php;
location / {
proxy_pass http://webserver;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Accept-Encoding ‘gzip’; #开启gzip缓存
proxy_set_header Accept-Encoding ”; #开启gzip缓存
proxy_ignore_headers “Cache-Control” “Expires”; #这段配置加上后,proxy_cache就能支持后台设定的expires
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404; #如果后端的服务器返回502、504、执行超时等错误,
#自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
proxy_cache cache_one; #进行缓存,使用Web缓存区cache_one
proxy_cache_valid 200 304 1h; #对不同的HTTP状态码设置不同的缓存时间
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args; #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,
#存储缓存内容到二级缓存目录内
add_header X-Cache HIT-cul; #查看缓存命中加上http标示头
if ( $request_method = “PURGE” ) {
rewrite ^(.*)$ /purge$1 last;
}
if ($http_Cache_Control = “no-cache”) {
rewrite ^(.*)$ /purge$1 last;
}
expires 1h;
}
location ~* /index_[0-9].shtml$ {
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webserver;
if ($http_Cache_Control = “no-cache”) {
break;
}
}
location ~.*.(php|jsp|cgi)?$ {
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webserver;
}
location ~ /purge(/.*){
allow x.x.x.x;
deny all;
error_page 405 =200 /purge$1;
proxy_cache_purge cache_one $host$1$is_args$args;
}
location /status {
stub_status on;
access_log off;
}
# log_format xxxx ‘$remote_addr – $remote_user [$time_local] “$request” ‘
# ‘$status $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” $http_x_forwarded_for’;
# access_log /data/nginxlog/Cachelogs/xxxx.log xxxx;
}
include vhost/*.conf;
}