Nginx 反向代理 twitter 遇到的问题

2017-10-15 22:08:57 +08:00
 luckyscript

昨天看到 v2 上有人反代谷歌,我想反代一下推特试试,但是搞了一天没有成功。

失败原因:首页代理成功,但是静态资源的链接并不是twitter.com这个域,而是 abs.twimg.com等类似的。

搜索资料发现用了subs_filter这个 Nginx 模块来替换网页中的东西,但是安装后发现并没有效果。

现在情况:首页反代成功,静态资源链接未能替换导致请求不到。

问:1. 这个模块是否有可以替换网页内容的功能(去 github 发现 2y 前更新的,issue 也都没管,资料很少) 2. 是否有其他模块可以做到这个功能 3. 是否需要用 lua 来自己搞下网站内容 4. 怎么学 lua

附配置文件:

location / {
	proxy_buffer_size 128k;
    proxy_buffers 32 64k;
    proxy_busy_buffers_size 256k;

    proxy_set_header Host   twitter.com;
    proxy_set_header Refer  twitter.com;

    subs_filter_types text/html text/css text/javascript;
    subs_filter 'pbs.twimg.com' 'example.com/pbs';
    subs_filter 'abs.twimg.com' 'example.com/abs';
    subs_filter 't.co' 'example.com/t.co';
    proxy_pass https://Twitter;
}

...
6016 次点击
所在节点    NGINX
11 条回复
vefawn1
2017-10-15 22:15:20 +08:00
试试把这些加到本地 hosts 里
104.244.46.148 cdn.syndication.twimg.com
104.244.46.148 m1.twitpic.com
104.244.46.148 twitpic.com
104.244.46.148 web1.twitpic.com
104.244.46.148 web10.twitpic.com
104.244.46.148 web2.twitpic.com
104.244.46.148 web3.twitpic.com
104.244.46.148 web4.twitpic.com
104.244.46.148 web5.twitpic.com
104.244.46.148 web6.twitpic.com
104.244.46.148 web7.twitpic.com
104.244.46.148 web8.twitpic.com
104.244.46.148 web9.twitpic.com
104.244.43.135 abs.twimg.com
104.244.43.135 g.twimg.com
104.244.43.135 image-proxy-origin.twimg.com
104.244.43.135 ma.twimg.com
104.244.43.135 o.twimg.com
104.244.43.135 p.twimg.com
104.244.43.135 pbs.twimg.com
104.244.43.135 r.twimg.com
104.244.43.135 syndication-o.twimg.com
104.244.43.135 syndication.twimg.com
104.244.43.135 ton.twimg.com
104.244.43.135 video.twimg.com
luckyscript
2017-10-15 22:24:03 +08:00
@vefawn1 umm,谢谢啊,但是目的是搞一下 nginx。
choury
2017-10-15 22:29:42 +08:00
subs_filter 需要关闭 gzip 压缩
Daniel65536
2017-10-15 22:42:17 +08:00
你反代的时候源站返回的是 gzip 之后的数据,然后直接拿去替换显然毛都查找不到。

除了在请求源站的时候强行关掉 gzip,更好的解决思路是这个: https://www.v2ex.com/t/234923
luckyscript
2017-10-15 22:46:17 +08:00
zlfzy
2017-10-16 00:05:56 +08:00
你搞反代不比用$$危险?
lslqtz
2017-10-16 00:25:10 +08:00
怎么感觉和我 n 年前反代 u2b 一样。。
Kokororin
2017-10-16 20:57:42 +08:00
akira
2017-10-17 02:37:00 +08:00
@zlfzy 如果上了 ssl 的话,然后限制下站点访问,可能这个会更安全
cue
2020-12-02 10:53:40 +08:00
楼主被封了没?
luckyscript
2020-12-02 17:47:55 +08:00
@cue 。。。几年前的玩具,早就不在跑了

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

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

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

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

© 2021 V2EX