Nginx反代的缓存配置

广告位招租,站内联系站长,仅支持虚拟币支付,500U/月

admin

Administrator
管理成员
动态请求不处理
代码:
location ~* \.(php|jsp|cgi|asp|aspx)$
{
    proxy_pass https://www.tear.cc/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_ssl_name $host;
    proxy_ssl_server_name on;
}
全局不缓存
代码:
location /
{
    proxy_pass https://www.tear.cc/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_ssl_name $host;
    proxy_ssl_server_name on;
    
    add_header X-Cache $upstream_cache_status;
        #Set Nginx Cache
        proxy_ignore_headers Set-Cookie Cache-Control expires;
        add_header Cache-Control no-cache;
    expires 12h;
}
静态资源缓存2天
代码:
location ~* \.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|ico|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma|css|js)$
{
    proxy_pass https://www.tear.cc/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_ssl_name $host;
    proxy_ssl_server_name on;
    
    add_header X-Cache $upstream_cache_status;
        #Set Nginx Cache

    proxy_ignore_headers Set-Cookie Cache-Control expires;
    proxy_cache cache_one;
    proxy_cache_key $host$uri$is_args$args;
    proxy_cache_valid 200 304 301 302 2d;
    expires 12h;
}

如果你正在使用宝塔面板使用反向代理,记得关掉默认的缓存功能,再把上面的代码复制到配置文件食用
 
后退
顶部