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

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";
  }
}
12052 次点击
所在节点    NGINX
28 条回复
Khlieb
2016-05-07 00:53:39 +08:00
手机版 502 了
Khlieb
2016-06-21 01:37:35 +08:00
全站 404 了
imlinhanchao
2016-09-09 21:18:04 +08:00
@chunchu https://github.com/imlinhanchao/ngx_proxy_wiki 所有语言的反代。(时隔多年,终于填坑
Michael2002
2017-02-14 18:23:33 +08:00
@bdbai 怎么改 DNS ?
bdbai
2017-02-14 21:51:28 +08:00
@Michael2002 网上搜一下公共 DNS
Michael2002
2017-03-23 07:08:59 +08:00
@bdbai 换什么 DNS 呢?
Michael2002
2017-03-23 07:16:11 +08:00
@bdbai 感觉很多 DNS 都不咋地
Michael2002
2017-04-21 13:10:40 +08:00
@bdbai 在吗?

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

https://tanronggui.xyz/t/249435

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

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

© 2021 V2EX