proxy_temp_path /data0/proxy_temp_path levels=1:2 key_zone=cache_one:200m inactive=1d max_size=30g;
upstream my_sever_pool{
server 192.168.1.2:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.3:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.4:80 weight=1 max_fails=2 fail_timeout=30s;
}
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forward-For $remote_addr;
proxy_pass ;
# root html;
#index index.html index.htm;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
#使用web缓存区cache_one
proxy_cache cache_one;
#对不同状态码设置不同缓存时间
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any im;
#设置web缓存的key值,nginx根据key值md5希哈存储缓存,这里根据“域名/URL 参数”组合成key。
proxy_cache_key $host$uri$is_args$args;
#反向代理,访问后端内容源服务器
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http:my_server_pool;
}
#用于清除缓存,假设一个URL为通过访问可以清除该URK缓存。
location ~ /purge(/.*)
{
#设定只允许指定的IP或IP段才可以清除URL缓存。
allow 127.0.0.1
allow 192.168.0.0/16;
deny all;
proxy_cache_purge cache_one $shot$1$is-args$args;
}
access_log 0ff
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass ;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}