如题!如何反向代理维基百科呢?
server
{
listen 443;
listen [::]:443;
server_name www.xxx.com;
ssl on;
ssl_certificate /home/sslkey/xxx.com.crt;
ssl_certificate_key /home/sslkey/xxx.com.key;
location / {
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
{
return 403;
}
proxy_set_header Host 'zh.wikipedia.org';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://zh.wikipedia.org/;
proxy_set_header Accept-Encoding "";
}
}
我用上面的配置反代维基,电脑访问正常,可是一用手机访问就自动跳到 zh.m.wikipedia.org 去了,我试着在配置中添加 if 语句进行判断,如果是手机的话 proxy_pass https://zh.m.wikipedia.org/,可是一用 if , proxy_pass 就会报错……怎么办呢?
server
{
listen 443;
listen [::]:443;
server_name www.xxx.com;
ssl on;
ssl_certificate /home/sslkey/xxx.com.crt;
ssl_certificate_key /home/sslkey/xxx.com.key;
location / {
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
{
return 403;
}
proxy_set_header Host 'zh.wikipedia.org';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://zh.wikipedia.org/;
proxy_set_header Accept-Encoding "";
}
}
我用上面的配置反代维基,电脑访问正常,可是一用手机访问就自动跳到 zh.m.wikipedia.org 去了,我试着在配置中添加 if 语句进行判断,如果是手机的话 proxy_pass https://zh.m.wikipedia.org/,可是一用 if , proxy_pass 就会报错……怎么办呢?