前期准备
需要准备的东西请查阅上篇反向代理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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| server { listen 80; listen [::]:80; server_name domain.name; rewrite ^ https://$server_name$request_uri? permanent; }
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name domain.name;
ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; ssl_prefer_server_ciphers on; ssl_certificate /path/cert/pem.pem; ssl_certificate_key /path/cert/key.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; 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 80; listen [::]:80; server_name m.domain.name; rewrite ^ https://$server_name$request_uri? permanent; }
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name m.domain.name;
ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; ssl_prefer_server_ciphers on; ssl_certificate /path/cert/pem.pem; ssl_certificate_key /path/cert/key.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; 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 80; listen [::]:80; server_name upload.domain.name; rewrite ^ https://$server_name$request_uri? permanent; }
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name upload.domain.name;
ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; ssl_prefer_server_ciphers on; ssl_certificate /path/cert/pem.pem; ssl_certificate_key /path/cert/key.key; ssl_session_cache shared:SSL:10m; 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的通配符证书。