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

2016-01-09 01:59:26 +08:00
 imlinhanchao

前阵子在 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";
  }
}
11665 次点击
所在节点    NGINX
28 条回复
Tink
2016-01-09 02:12:32 +08:00
我也反代了一个,手机版貌似也有问题,就没管
just1
2016-01-09 02:30:37 +08:00
做一个通用反代规则就可以了,所以网站自动反代
marenight
2016-01-09 02:37:39 +08:00
手机浏览器拦截了,报告隐私风险。
Zohar
2016-01-09 07:32:54 +08:00
chunchu
2016-01-09 08:30:11 +08:00
最下面的 server 前面少了一个字母 s
leakeung
2016-01-09 08:31:56 +08:00
过断 mark 赞
imlinhanchao
2016-01-09 09:11:52 +08:00
@marenight 难道证书不认?
@chunchu 哈~可能贴上来不小心删到了。
@just1 好像可行,回头试试。
chunchu
2016-01-09 10:07:25 +08:00
期待楼主对所有语言的反代
Khlieb
2016-01-09 11:21:59 +08:00
bdbai
2016-01-09 11:23:09 +08:00
感觉中文版只是 DNS 污染,换个 DNS 就能访问了。
imlinhanchao
2016-01-09 11:55:38 +08:00
@bdbai 用 hosts 确实可以访问,不过图片不知道为啥看不了。
bdbai
2016-01-09 12:40:37 +08:00
@imlinhanchao 图片用的域名也得改 host ,不过改个 DNS 就一劳永逸了。
Khlieb
2016-01-09 13:06:32 +08:00
@bdbai DNSᴄʀʏᴘᴛ 无压力
Guenlay
2016-01-09 16:40:09 +08:00
multy subs_filter 似乎是 1.9.3 以后才支持
Slienc7
2016-01-09 18:16:05 +08:00
为何不直接上数据库做镜像。
chunchu
2016-01-09 22:47:07 +08:00
nginx version: nginx/1.9.3

测试了一下,图片不能正确显示,我看楼主的图片可以正常显示,不知道是什么原因。
chunchu
2016-01-09 22:56:08 +08:00
找到原因了,我的 wildcard 只能对*.xxx.org 有效,对 up.w.xxx.org 不能识别为安全连接
bumz
2016-01-10 14:51:35 +08:00
@Khlieb 这是什么字符?ᴀ ʙ ᴄ ᴅ ᴇ ғ ɢ ʜ ɪ ᴊ ᴋ ʟ ᴍ ɴ ᴏ ᴘ ǫ ʀ s ᴛ ᴜ ᴠ ᴡ x ʏ ᴢ
Khlieb
2016-01-10 17:15:21 +08:00
@bumz 这是小型大写字母, Unicode 里面有独立的字符,但有些字体可以用 OpenType 变换出来。
Khlieb
2016-01-10 17:17:27 +08:00

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

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

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

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

© 2021 V2EX