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

Nginx 反向代理 twitter 遇到的问题

  •  
  •   luckyscript · 2017-10-15 22:08:57 +08:00 · 5967 次点击
    这是一个创建于 2356 天前的主题,其中的信息可能已经有所发展或是发生改变。

    昨天看到 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;
    }
    
    ...
    
    11 条回复    2020-12-02 17:47:55 +08:00
    vefawn1
        1
    vefawn1  
       2017-10-15 22:15:20 +08:00 via Android
    试试把这些加到本地 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
        2
    luckyscript  
    OP
       2017-10-15 22:24:03 +08:00
    @vefawn1 umm,谢谢啊,但是目的是搞一下 nginx。
    choury
        3
    choury  
       2017-10-15 22:29:42 +08:00   ❤️ 2
    subs_filter 需要关闭 gzip 压缩
    Daniel65536
        4
    Daniel65536  
       2017-10-15 22:42:17 +08:00   ❤️ 1
    你反代的时候源站返回的是 gzip 之后的数据,然后直接拿去替换显然毛都查找不到。

    除了在请求源站的时候强行关掉 gzip,更好的解决思路是这个: https://www.v2ex.com/t/234923
    luckyscript
        5
    luckyscript  
    OP
       2017-10-15 22:46:17 +08:00
    zlfzy
        6
    zlfzy  
       2017-10-16 00:05:56 +08:00 via iPhone
    你搞反代不比用$$危险?
    lslqtz
        7
    lslqtz  
       2017-10-16 00:25:10 +08:00
    怎么感觉和我 n 年前反代 u2b 一样。。
    Kokororin
        8
    Kokororin  
       2017-10-16 20:57:42 +08:00 via iPhone   ❤️ 1
    akira
        9
    akira  
       2017-10-17 02:37:00 +08:00
    @zlfzy 如果上了 ssl 的话,然后限制下站点访问,可能这个会更安全
    cue
        10
    cue  
       2020-12-02 10:53:40 +08:00
    楼主被封了没?
    luckyscript
        11
    luckyscript  
    OP
       2020-12-02 17:47:55 +08:00
    @cue 。。。几年前的玩具,早就不在跑了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1003 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:11 · PVG 06:11 · LAX 15:11 · JFK 18:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.