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

反向代理中文维基百科(包含手机版页面)

  •  
  •   imlinhanchao ·
    imlinhanchao · 2016-01-09 01:59:26 +08:00 · 11644 次点击
    这是一个创建于 3024 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前阵子在 vps 上弄了一个中文维基百科的反向代理,但是一直存在手机端不能用的问题(会跳转到手机版的维基百科)。刚刚终于把这个问题解决掉了: https://w.sxisa.org
    https 的证书是用的 Let's Encrypt
    下面是 nginx 的配置:

    server {
      server_name w.sxisa.org;
      listen 80;
      rewrite ^/(.*) https://$server_name/$1 permanent;
    }
    
    server {
      server_name w.sxisa.org;
      listen 443;
    
      ssl on;
      ssl_certificate      证书;
      ssl_certificate_key  证书;
    
      location / {
        proxy_pass https://zh.wikipedia.org;
        proxy_buffering off;
    
        proxy_cookie_domain zh.wikipedia.org w.sxisa.org;
        proxy_redirect https://zh.wikipedia.org/ /;
        proxy_redirect https://zh.m.wikipedia.org/ https://m.w.sxisa.org/;
    
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header Accept-Encoding ''; 
        proxy_set_header referer "https://zh.wikipedia.org$request_uri";
    
        subs_filter_types text/css text/xml text/javascript;
        subs_filter '维基百科' '创软维基百科镜像';
        subs_filter zh.wikipedia.org w.sxisa.org;
        subs_filter upload.wikimedia.org up.w.sxisa.org;
        subs_filter zh.m.wikipedia.org m.w.sxisa.org;
      }
      location https://zh.m.wikipedia.org/{
        rewrite ^/(.*) https://m.w.sxisa.org/$1 permanent;
      }
    }
    
    server {
      server_name m.w.sxisa.org;
      listen 80;
      rewrite ^/(.*) https://$server_name/$1 permanent;
    }
    
    server {
      server_name m.w.sxisa.org;
      listen 443;
    
      ssl on;
      ssl_certificate      证书;
      ssl_certificate_key  证书;
    
      location / {
        proxy_pass https://zh.m.wikipedia.org;
        proxy_buffering off;
    
        proxy_redirect https://zh.m.wikipedia.org/ /;
        proxy_cookie_domain zh.m.wikipedia.org m.w.sxisa.org;
    
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header Accept-Encoding ''; 
        proxy_set_header referer "https://zh.m.wikipedia.org$request_uri";
    
        subs_filter_types text/css text/xml text/javascript;
        subs_filter '维基百科' '创软维基百科镜像';
        subs_filter zh.wikipedia.org w.sxisa.org;
        subs_filter zh.m.wikipedia.org m.w.sxisa.org;
        subs_filter upload.wikimedia.org up.w.sxisa.org;
      }
    }
    
    server {
      server_name up.w.sxisa.org;
      listen 80;
      rewrite ^/(.*) https://$server_name/$1 permanent;
    }
    
    erver {
      server_name up.w.sxisa.org;
      listen 443;
    
      ssl on;
      ssl_certificate      证书;
      ssl_certificate_key  证书;
    
      location / {
        proxy_pass https://upload.wikimedia.org;
        proxy_cookie_domain upload.wikimedia.org up.w.sxisa.org;
        proxy_buffering off;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header referer "https://upload.wikimedia.org$request_uri";
      }
    }
    
    28 条回复    2017-04-21 13:10:40 +08:00
    Tink
        1
    Tink  
       2016-01-09 02:12:32 +08:00 via iPhone
    我也反代了一个,手机版貌似也有问题,就没管
    just1
        2
    just1  
       2016-01-09 02:30:37 +08:00 via Android
    做一个通用反代规则就可以了,所以网站自动反代
    marenight
        3
    marenight  
       2016-01-09 02:37:39 +08:00
    手机浏览器拦截了,报告隐私风险。
    Zohar
        4
    Zohar  
       2016-01-09 07:32:54 +08:00
    chunchu
        5
    chunchu  
       2016-01-09 08:30:11 +08:00 via iPhone
    最下面的 server 前面少了一个字母 s
    leakeung
        6
    leakeung  
       2016-01-09 08:31:56 +08:00
    过断 mark 赞
    imlinhanchao
        7
    imlinhanchao  
    OP
       2016-01-09 09:11:52 +08:00 via Android
    @marenight 难道证书不认?
    @chunchu 哈~可能贴上来不小心删到了。
    @just1 好像可行,回头试试。
    chunchu
        8
    chunchu  
       2016-01-09 10:07:25 +08:00
    期待楼主对所有语言的反代
    Khlieb
        9
    Khlieb  
       2016-01-09 11:21:59 +08:00 via Android
    bdbai
        10
    bdbai  
       2016-01-09 11:23:09 +08:00 via iPhone
    感觉中文版只是 DNS 污染,换个 DNS 就能访问了。
    imlinhanchao
        11
    imlinhanchao  
    OP
       2016-01-09 11:55:38 +08:00
    @bdbai 用 hosts 确实可以访问,不过图片不知道为啥看不了。
    bdbai
        12
    bdbai  
       2016-01-09 12:40:37 +08:00 via iPhone
    @imlinhanchao 图片用的域名也得改 host ,不过改个 DNS 就一劳永逸了。
    Khlieb
        13
    Khlieb  
       2016-01-09 13:06:32 +08:00 via Android
    @bdbai DNSᴄʀʏᴘᴛ 无压力
    Guenlay
        14
    Guenlay  
       2016-01-09 16:40:09 +08:00
    multy subs_filter 似乎是 1.9.3 以后才支持
    Slienc7
        15
    Slienc7  
       2016-01-09 18:16:05 +08:00
    为何不直接上数据库做镜像。
    chunchu
        16
    chunchu  
       2016-01-09 22:47:07 +08:00
    nginx version: nginx/1.9.3

    测试了一下,图片不能正确显示,我看楼主的图片可以正常显示,不知道是什么原因。
    chunchu
        17
    chunchu  
       2016-01-09 22:56:08 +08:00
    找到原因了,我的 wildcard 只能对*.xxx.org 有效,对 up.w.xxx.org 不能识别为安全连接
    bumz
        18
    bumz  
       2016-01-10 14:51:35 +08:00
    @Khlieb 这是什么字符?ᴀ ʙ ᴄ ᴅ ᴇ ғ ɢ ʜ ɪ ᴊ ᴋ ʟ ᴍ ɴ ᴏ ᴘ ǫ ʀ s ᴛ ᴜ ᴠ ᴡ x ʏ ᴢ
    Khlieb
        19
    Khlieb  
       2016-01-10 17:15:21 +08:00 via Android
    @bumz 这是小型大写字母, Unicode 里面有独立的字符,但有些字体可以用 OpenType 变换出来。
    Khlieb
        20
    Khlieb  
       2016-01-10 17:17:27 +08:00 via Android
    Khlieb
        21
    Khlieb  
       2016-05-07 00:53:39 +08:00 via Android
    手机版 502 了
    Khlieb
        22
    Khlieb  
       2016-06-21 01:37:35 +08:00
    全站 404 了
    imlinhanchao
        23
    imlinhanchao  
    OP
       2016-09-09 21:18:04 +08:00
    @chunchu https://github.com/imlinhanchao/ngx_proxy_wiki 所有语言的反代。(时隔多年,终于填坑
    Michael2002
        24
    Michael2002  
       2017-02-14 18:23:33 +08:00
    @bdbai 怎么改 DNS ?
    bdbai
        25
    bdbai  
       2017-02-14 21:51:28 +08:00 via Android
    @Michael2002 网上搜一下公共 DNS
    Michael2002
        26
    Michael2002  
       2017-03-23 07:08:59 +08:00
    @bdbai 换什么 DNS 呢?
    Michael2002
        27
    Michael2002  
       2017-03-23 07:16:11 +08:00
    @bdbai 感觉很多 DNS 都不咋地
    Michael2002
        28
    Michael2002  
       2017-04-21 13:10:40 +08:00
    @bdbai 在吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   900 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:53 · PVG 04:53 · LAX 13:53 · JFK 16:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.