技术解析

Nginx 反代 Google 返回 HTTP 301
0
2021-05-26 22:32:37
idczone
配置如下
server {
listen 80;
server_name g.mydomain.com;
location / {
sub_filter www.google.com g.mydomain.com;
proxy_pass http://g.mydomain.com;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forward美国服务器ed-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http//$host;
}
}
用ssl吧。

proxy_pass https://www.google.com;
proxy_set_header Referer https://www.google.com;

效果相同,依然返回 301 Moved Permanently (from cache)

ssl很麻烦吧,有永久免费的吗

要用SSL

你没带上cookie当然会跳转

请教怎么带cookie

http://wrfly.kfd.me/Nginx%E6%90%AD%E5%BB%BA%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1/
安利一波同学做的镜像~

但是Cookie是哪里来的呢?
我这样尝试过,用curl请求google,获取cookie,再用curl 带刚获取的cookie请求,google返回错误界面。

应该可以用本机的吧

server {
listen 443;
server_name g.mydomain.com;
ssl on;
ssl_certificate /ssl/g.mydomain.com.crt;
ssl_certificate_key /ssl/g.mydomain.com.key;
location / {
proxy_cookie_domain www.google.com $host;
sub_filter www.google.com $host;
sub_filter_once off;
proxy_pass http://google;
proxy_redirect https://www.google.com/ /;
proxy_set_header HOST "www.google.com";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "";
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Accept-Language "zh-CN";
proxy_set_header Cookie "PREF=ID=047818f19f6de346:U=0f622f33dd8549d11:FF=25:LD=zh-CN:NW=1:TM=1325238577:LM=1332342444:GM=5:SG=1:S=rE01SyJh2w1IQ-Maw";
}
}
参照博客内容配置如上,依然不可以,依然返回301

head 里面set的cookie啊,你本地curl的cookie好像有问题,具体我也说不上,那个博客里面的cookie是好的,你可以试一下那里面设置的cookie,语言啊啥的都能调

upstream复制全了么- -

复制全了,肯定能连上服务器,要不也不会返回301

log_format g.yh.gs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server
{
listen 443;
server_name g.yh.gs;
^/(.*) https://$server_name$1 permanent;
ssl on;
ssl_certificate /usr/local/nginx/ssl/1_g.yh.gs_bundle.crt;
ssl_certificate_key /usr/local/nginx/ssl/2_g.yh.gs.key;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
80;
location / {
proxy_redirect off;
proxy_cookie_domain google.com xxx.xxx;
proxy_pass https://www.google.co.jp/;
proxy_set_header Accept-Encoding "";
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Accept-Language "zh-CN";
proxy_set_header Cookie "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=zh-CN:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
}
}

server {
listen 80;
server_name g.yh.gs;
rewrite ^(.*) https://$server_name$1 permanent;
}

参考我的



昨天还不行,今天起床一看什么都好了,完全莫名其妙

记得保存配置副本- -

嗯,做了个备份

ngx_http_google_filter_module
google on;
google_scholar on;
google_language zh-CN;
说这么多应该够了,嗯。。

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服