Nginx 反代 Google 返回 HTTP 301 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ivito
V2EX    NGINX

Nginx 反代 Google 返回 HTTP 301

  •  
  •   ivito
    fireboyvt Jul 3, 2015 4723 views
    This topic created in 3952 days ago, the information mentioned may be changed or developed.
    配置如下
    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-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Referer http//$host;
    }
    }
    19 replies    2015-07-04 15:37:02 +08:00
    cnly1987
        1
    cnly1987  
       Jul 3, 2015 via Android
    用ssl吧。
    wico77
        2
    wico77  
       Jul 3, 2015
    proxy_pass https://www.google.com;
    proxy_set_header Referer https://www.google.com;
    ivito
        3
    ivito  
    OP
       Jul 3, 2015
    @wico77 效果相同,依然返回 301 Moved Permanently (from cache)
    ivito
        4
    ivito  
    OP
       Jul 3, 2015
    @cnly1987 ssl很麻烦吧,有永久免费的吗
    wico77
        5
    wico77  
       Jul 3, 2015
    要用SSL
    yeyeye
        6
    yeyeye  
       Jul 3, 2015
    你没带上cookie当然会跳转
    ltm
        7
    ltm  
       Jul 3, 2015 via Android
    @yeyeye 请教怎么带cookie
    ltm
        9
    ltm  
       Jul 3, 2015
    @Orzzzz 但是Cookie是哪里来的呢?
    我这样尝试过,用curl请求google,获取cookie,再用curl 带刚获取的cookie请求,google返回错误界面。
    yeyeye
        10
    yeyeye  
       Jul 3, 2015
    @ltm 应该可以用本机的吧
    ivito
        11
    ivito  
    OP
       Jul 3, 2015
    @ltm 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
    Orzzzz
        12
    Orzzzz  
       Jul 4, 2015
    @ltm head 里面set的cookie啊,你本地curl的cookie好像有问题,具体我也说不上,那个博客里面的cookie是好的,你可以试一下那里面设置的cookie,语言啊啥的都能调
    Orzzzz
        13
    Orzzzz  
       Jul 4, 2015
    @ivito upstream复制全了么- -
    ivito
        14
    ivito  
    OP
       Jul 4, 2015 via iPhone
    @Orzzzz 复制全了,肯定能连上服务器,要不也不会返回301
    hiboshi
        15
    hiboshi  
       Jul 4, 2015
    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;
    #rewrite ^/(.*) 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;
    #listen 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;
    }


    参考我的
    ivito
        16
    ivito  
    OP
       Jul 4, 2015
    @Orzzzz
    @hiboshi
    昨天还不行,今天起床一看什么都好了,完全莫名其妙
    Orzzzz
        17
    Orzzzz  
       Jul 4, 2015
    @ivito 记得保存配置副本- -
    ivito
        18
    ivito  
    OP
       Jul 4, 2015 via iPhone
    @Orzzzz 嗯,做了个备份
    WeeH9T
        19
    WeeH9T  
       Jul 4, 2015
    ngx_http_google_filter_module

    google on;
    google_scholar on;
    google_language zh-CN;

    说这么多应该够了,嗯。。
    About     Help     Advertise     Blog     API     FAQ     Solana     1231 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 68ms UTC 17:36 PVG 01:36 LAX 10:36 JFK 13:36
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86