技术解析
前阵子在 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";
}
}