a.com 中包含一张图片 b.com ,我用 c.com 去反代 a.com ,但是想把反代后的结果调用的图片 b.com 替换为其它图片,使用subs_filter b.com/123.jpg c.com/456.jpg;不起作用,请问应该怎样替换 a.com 域名中的图片地址 b.com ?

a.com 中包含一张图片 b.com ,我用 c.com 去反代 a.com ,但是想把反代后的结果调用的图片 b.com 替换为其它图片,使用subs_filter b.com/123.jpg c.com/456.jpg;不起作用,请问应该怎样替换 a.com 域名中的图片地址 b.com ?
完整配置文件如下,需求是将http://search.xiaoz.me中包含的图片http://pic.bsdev.cn替换为HTTPS:https://pic.bsdev.cn
server { listen 443; server_name so.xiaoz.me; ssl on; ssl_certificate /etc/letsencrypt/live/so.xiaoz.me/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/so.xiaoz.me/privkey.pem; location / { proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_pass http://search.xiaoz.me; subs_filter_types text/html text/css text/xml; subs_filter http://pic.bsdev.cn https://pic.bsdev.cn; } } server { listen 80; server_name so.xiaoz.me; rewrite ^(.*) https://so.xiaoz.me$1 permanent; } 此贴终结,无法使用subs_filter替换的原因是开启了Gzip导致,6楼回复正解。在location中加入proxy_set_header Accept-Encoding "";,重启nginx后完美解决。被坑了几个小时
1 SeeMeTomorrow May 28, 2016 via iPhone 建议把完整配置文件贴上来 |
2 lslqtz May 28, 2016 subs?不是 sub 嘛? |
3 xiaoz OP @SeeMeTomorrow 您好,完整配置文件已经贴上来了,谢谢。 |
4 xiaoz OP @lslqtz 不知道新版本中是否将 sub 改成了 subs ,因为我使用 sub 的时候报语法错误,根据官方的帮助文档: https://www.nginx.com/resources/wiki/modules/substitutions/?highlight=subs_filter 来看的话也是使用的 subs |
5 lslqtz2 May 28, 2016 @xiaoz 应该是我们模块不同?不清楚,我这边保存的文档说是 sub 测试有效 http://www.ttlsa.com/linux/nginx-modules-ngx_http_sub_module/ |
6 tammy May 28, 2016 ``` proxy_set_header Accept-Encoding "";#关闭 Gzip 是 subs_filter 能正常工作 ``` 来自: http://blog.iplayloli.com/nginx-reserve-proxy-google-gravatar.html 话说怎么高亮代码? |
7 Tink PRO 我感觉没什么问题 |
14 fakefish May 29, 2016 图片就不要 gzip 了嘛 没用 |
16 Daniel65536 May 29, 2016 proxy_set_header Accept-Encoding ""浪费流量。 应该上 ngx_http_gunzip_module ,用 proxy_pass 来中转下就好,可以大幅度节约流量开支。 |
17 a href="/member/xiaoz" class="dark">xiaoz OP @Daniel65536 好的,多谢指点 |