前期准备
需要准备的东西请查阅上篇反向代理Google的前言,因为需要反代多个域名,所以需要设置多个域名解析记录,分别为domain.name、m.domain.name、upload.domain.name。
配置Nginx反代
Nginx需编译安装nginx_substitutions_filter模块。
Nginx配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| server { listen 80; listen [::]:80;
server_name domain.name m.domain.name upload.domain.name; return 301 https://$host$request_uri; }
server { listen 443 ssl; listen [::]:443 ssl; http2 on;
server_name domain.name;
ssl_certificate /path/cert.crt; ssl_certificate_key /path/cert.key; location / { proxy_pass https://zh.wikipedia.org; proxy_buffering off; proxy_cookie_domain zh.wikipedia.org domain.name; proxy_redirect https://zh.wikipedia.org/ /; proxy_redirect https://zh.m.wikipedia.org/ https://m.domain.name/; proxy_set_header Accept-Encoding ""; proxy_set_header X-Real_IP $remote_addr; proxy_set_header User-Agent $http_user_agent; proxy_set_header referer https://zh.wikipedia.org$request_uri;
subs_filter_types text/css text/xml text/javascript application/javascript application/json; subs_filter zh.wikipedia.org domain.name; subs_filter zh.m.wikipedia.org m.domain.name; subs_filter upload.wikimedia.org upload.domain.name; }
location https://zh.m.wikipedia.org/{ rewrite ^/(.*) https://m.domain.name/$1 permanent; } }
server { listen 443 ssl; listen [::]:443 ssl; http2 on;
server_name m.domain.name;
ssl_certificate /path/cert.crt; ssl_certificate_key /path/certkey; 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.domain.name; proxy_set_header Accept-Encoding ""; proxy_set_header X-Real_IP $remote_addr; proxy_set_header User-Agent $http_user_agent; proxy_set_header referer https://zh.m.wikipedia.org$request_uri;
subs_filter_types text/css text/xml text/javascript application/javascript application/json; subs_filter zh.wikipedia.org domain.name; subs_filter zh.m.wikipedia.org m.domain.name; subs_filter upload.wikimedia.org upload.domain.name; } }
server { listen 443 ssl; listen [::]:443 ssl; http2 on;
server_name upload.domain.name;
ssl_certificate /path/cert.crt; ssl_certificate_key /path/cert.key; location / { proxy_pass https://upload.wikimedia.org; proxy_cookie_domain upload.wikimedia.org upload.domain.name; 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; } }
|
后记
domain.name替换成你自己的域名,为域名添加SSL证书,可以使用Let’s Encrypt的通配符证书。