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

nginx 反代里缓存怎么清理

  •  
  •   phithon ·
    phith0n · 2015-05-27 23:14:37 +08:00 · 3578 次点击
    这是一个创建于 3259 天前的主题,其中的信息可能已经有所发展或是发生改变。

    遇到一个奇葩问题。
    反代http://a.com/ 反代了 http://b.com/ ,我用了subs_filter替换其中的一个字符串。
    但实际效果是没有替换成功。
    这是我的配置:

    location / {
                            proxy_pass http://b.com;
                            proxy_cookie_domain b.com a.com;
                            proxy_buffering off;
                            proxy_http_version 1.1;
                            proxy_ignore_headers Expires Vary Cache-Control X-Accel-Expires ;
                            proxy_set_header Accept-Encoding "";
                            proxy_set_header X-Real-IP $remote_addr;
                            proxy_set_header User-Agent $http_user_agent;
                            proxy_set_header If-Modified-Since "";
                            subs_filter xxxxxx yyyyyy;
                    }
    

    我怀疑是缓存的问题,于是请求的时候请求了http://a.com/?a ,于是就好了。
    就是 http://a.com/ 的时候有问题。
    我用chrome的隐身模式访问的,应该不是本地缓存的问题。
    于是我把nginx的debug日志打开,得到的是这样一个warn:

    2015/05/27 23:01:47 [warn] 15942#0: *32 http subs filter header ignored, this may be a compressed response. while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: a.com, request: "GET / HTTP/1.1", upstream: "http://yyy.yyy.yyy.yyy:80/", host: "a.com"
    

    日志意思是不是返回的包是gzip压缩过的,所以替换不了。但实际上我设置了Accept-Encoding:"",而且请求/?a的时候却是好的。所以我排除了compressed的原因。
    求问各位v友有没有遇到过的

    7 条回复    2015-05-29 11:21:52 +08:00
    wy315700
        1
    wy315700  
       2015-05-27 23:21:15 +08:00
    看说明是因为接收到的是压缩数据,所以无法替换
    phithon
        2
    phithon  
    OP
       2015-05-27 23:24:23 +08:00
    @wy315700
    那提示只是maybe。我后面分析了:
    “日志意思是不是返回的包是gzip压缩过的,所以替换不了。但实际上我设置了Accept-Encoding:"",而且请求/?a的时候却是好的。所以我排除了compressed的原因。”
    应该不是这个原因,如果是这个原因,又如何解决呢?
    LazyZhu
        3
    LazyZhu  
       2015-05-27 23:36:05 +08:00
    尝试开启gunzip,不管如何都尝试解压.
    http://nginx.org/en/docs/http/ngx_http_gunzip_module.html
    ryd994
        4
    ryd994  
       2015-05-28 04:11:22 +08:00 via Android
    如果没有配置过proxy cache的话是不会缓存的
    accept encoding上游可能不遵守
    你用chrome看看返回的header到底有没有压缩
    另外proxy buffer off是比较作死的设置
    @LazyZhu gunzip是在最后输出才解压吧……
    phithon
        5
    phithon  
    OP
       2015-05-28 11:49:54 +08:00
    @ryd994 感觉不像是上游不遵守压,访问 /?a 就是好的。如果不遵守不应该都不行才对?
    ryd994
        6
    ryd994  
       2015-05-28 11:57:03 +08:00
    @phithon 不一定,有些比较二的设置会这样:
    不带参数的直接取缓存或者静态,带参数的转发后端(PHP?)
    后端不加压缩header的话,web服务器是不会随便压的

    总之你先看看客户端接收到的header有没有不同
    phithon
        7
    phithon  
    OP
       2015-05-29 11:21:52 +08:00
    @ryd994 从我反代服务器返回的数据是Content-Encoding:gzip过的。
    但我加/?a返回包里也有这个头Content-Encoding:gzip
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1986 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:14 · PVG 00:14 · LAX 09:14 · JFK 12:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.