V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
xiaoz
V2EX  ›  NGINX

Nginx 反向代理怎样设置某个目录不缓存?

  •  
  •   xiaoz ·
    helloxz · 2018-05-25 14:45:11 +08:00 · 4170 次点击
    这是一个创建于 2134 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前的反代配置如下:

    proxy_cache_path /data/caches/xxx.com levels=1:2 keys_zone=gravatar:50m inactive=30m max_size=50m;
    server {
      	listen 80;
        server_name xxx.com;
        
        
        charset utf-8,gbk;
            location / {
               proxy_pass http://cn.gravatar.com;
               proxy_redirect off;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_cache gravatar;
               proxy_cache_valid  200 304 301 7d;
               proxy_cache_valid  500 502 503 504 0s;
               proxy_cache_valid any 7d;
               proxy_cache_min_uses 1;
               expires 12h;
        }
    }
    

    这样的配置是带有全局缓存的,假如我只希望 xxx.com/admin 这个路径不带有缓存,该如何配置?

    3 条回复    2018-05-25 16:34:36 +08:00
    Lax
        1
    Lax  
       2018-05-25 15:31:35 +08:00   ❤️ 1
    再加一个 location
    location /admin {
    proxy_pass ...;
    }
    hisys
        2
    hisys  
       2018-05-25 16:16:26 +08:00   ❤️ 1
    在一楼基础上添加一行:
    proxy_cache_valid any 0s;
    xiaoz
        3
    xiaoz  
    OP
       2018-05-25 16:34:36 +08:00
    @Lax
    @hisys
    好的,谢谢大佬,我试试。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3245 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:55 · PVG 19:55 · LAX 04:55 · JFK 07:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.