美文网首页nginx
nginx缓存不起作用问题解决方法

nginx缓存不起作用问题解决方法

作者: think_lonely | 来源:发表于2017-11-16 10:57 被阅读561次

    1. nginx不缓存原因

    默认情况下,nginx是否缓存是由nginx缓存服务器与源服务器共同决定的, 缓存服务器需要严格遵守源服务器响应的header来决定是否缓存以及缓存的时常。header主要有如下:

    复制代码代码如下:

    Cache-control:no-cache、no-store

    如果出现这两值,nginx缓存服务器是绝对不会缓存的

    复制代码代码如下:

    Expires:1980-01-01

    如果出现日期比当前时间早,也不会缓存。

    2. 解决不缓存方案

    2.1 方法一:

    修改程序或者源服务器web程序响应的header

    2.2 方法二:

    nginx代理直接加上如下一句:

    复制代码代码如下:

    proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;

    server {

    listen      80;

    listen      [::]:80;

    server_name  镜像服务器主机名;

    location / {

    proxy_pass http://www.nuget.org;

    proxy_cache nuget-cache;

    proxy_cache_valid 168h;

    proxy_ignore_headers Set-Cookie Cache-Control;

    proxy_hide_header Cache-Control;

    proxy_hide_header Set-Cookie;

    }

    }

    相关文章

      网友评论

        本文标题:nginx缓存不起作用问题解决方法

        本文链接:https://www.haomeiwen.com/subject/haflvxtx.html