nginx 反向代理替换图片的问题

2016 年 5 月 28 日
 xiaoz

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

7898 次点击
所在节点    NGINX
17 条回复
SeeMeTomorrow
2016 年 5 月 28 日
建议把完整配置文件贴上来
lslqtz
2016 年 5 月 28 日
subs?不是 sub 嘛?
xiaoz
2016 年 5 月 28 日
@SeeMeTomorrow 您好,完整配置文件已经贴上来了,谢谢。
xiaoz
2016 年 5 月 28 日
@lslqtz 不知道新版本中是否将 sub 改成了 subs ,因为我使用 sub 的时候报语法错误,根据官方的帮助文档: https://www.nginx.com/resources/wiki/modules/substitutions/?highlight=subs_filter 来看的话也是使用的 subs
lslqtz2
2016 年 5 月 28 日
@xiaoz 应该是我们模块不同?不清楚,我这边保存的文档说是 sub 测试有效
http://www.ttlsa.com/linux/nginx-modules-ngx_http_sub_module/
tammy
2016 年 5 月 28 日
```
proxy_set_header Accept-Encoding "";#关闭 Gzip 是 subs_filter 能正常工作
```

来自: http://blog.iplayloli.com/nginx-reserve-proxy-google-gravatar.html

话说怎么高亮代码?
Tink
2016 年 5 月 28 日
我感觉没什么问题
xiaoz
2016 年 5 月 28 日
@Tink 但实际没有替换成功
xiaoz
2016 年 5 月 28 日
@tammy V2 的回复不支持 markdown ,所以高亮不了,发表主题的话是支持 markdown 的
xiaoz
2016 年 5 月 28 日
@lslqtz2 你 nginx 哪个版本的呢?我是按照官方文档安装的那个模块
xiaoz
2016 年 5 月 28 日
@tammy 感谢回复,终于排查到原因就是因 Gzip 影响导致 subs_filter 不起作用,关闭 Gzip 后终于正常了,非常感谢。
lslqtz
2016 年 5 月 28 日
@xiaoz 最新。
lslqtz
2016 年 5 月 28 日
@tammy 忘了 gzip ,我也来感谢一下。
@xiaoz 我表示不关 gzip 也能用,所以就没有在意。
fakefish
2016 年 5 月 29 日
图片就不要 gzip 了嘛 没用
xiaoz
2016 年 5 月 29 日
@fakefish 不是图片 gzip 是整个网页中用了,导致 subs_filter 对整个网页不起作用。
Daniel65536
2016 年 5 月 29 日
proxy_set_header Accept-Encoding ""浪费流量。
应该上 ngx_http_gunzip_module ,用 proxy_pass 来中转下就好,可以大幅度节约流量开支。
xiaoz
2016 年 5 月 29 日
@Daniel65536 好的,多谢指点

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/281913

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX