,请问现在怎么用 nginx 反向代理 google - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
< href="http://trac.nginx.org/nginx/report" target="_blank">NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
sadan9
V2EX    NGINX

,请问现在怎么用 nginx 反向代理 google

  •  
  •   sadan9 2014-07-02 07:56:31 +08:00 12227 次点击
    这是一个创建于 4168 天前的主题,其中的信息可能已经有所发展或是发生改变。
    试过各种配置,但一直会被重定向到www.google.com.hk之类的网址上。
    9 条回复    2015-09-17 00:29:43 +08:00
    danbao
        1
    danbao  
       2014-07-02 09:54:39 +08:00   1
    server {
    listen 443 default ssl;
    listen [::]:443;
    server_name google.hahahahhahahahha.com;
    #1,设置反向代理的域名
    ssl on;
    ssl_certificate /cert/hahahahhahahahha.cer;
    ssl_certificate_key /cert/hahahahhahahahha.pem;
    location / {
    proxy_redirect off;
    proxy_pass https://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 "";
    #2,如果没有此项,当通过反向代理访问时会被重定向到google的站点,而不能通过反向代理访问
    proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.49 Safari/537.36";
    #3,可选,可以通过此项设置google打开的默认界面风格,此处呈现为平板的风格,如果不设置,google会自动根据浏览器判
    proxy_set_header Accept-Language "zh-CN";
    #4,可选,设置界面呈现的语言,如果不设置,google会自动根据浏览器判断
    proxy_set_header Cookie "PREF=ID=xxxxxx:U=yyyyy:FF=0:LD=zh-CN:NW=1:CR=2:TM=zzzz:LM=mmmmm:GM=1:SG=1:S=-nnnnn";
    #5,可选,设置cookie处理个性化设置,重点为:NW=1表示结果在新窗口中打开,LD=zh-CN表示语言为简体中文,此项将覆盖#4中的设置。(此处某些数据已编辑处理)
    sub_filter www.google.com g.linzhen.net;
    #6,可选,将页面中的 www.google.com 替换为g.linzhen.net,否则点击某些链接会跳回到google官方。
    sub_filter_once off;
    }
    }

    这是我的配置,带HTTPS的
    iCodex
        2
    iCodex  
       2014-07-02 09:59:46 +08:00
    cat >/usr/local/nginx/conf/_proxy.inc <<EOF
    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;
    proxy_buffer_size 64k;
    proxy_buffers 32 32k;
    proxy_busy_buffers_size 128k;
    proxy_cache_revalidate on;
    proxy_redirect off;
    proxy_hide_header Vary;
    proxy_set_header Accept-Encoding '';
    proxy_set_header Host \$proxy_host;
    proxy_set_header Referer \$proxy_host;
    proxy_set_header Cookie \$http_cookie;
    proxy_pass_header Set-Cookie;
    client_max_body_size 100m;
    client_body_buffer_size 128k;
    add_header X-Via "Proxy";
    EOF

    server {
    resolver 8.8.8.8;
    listen 80;
    server_name gg.org;

    location / {
    subs_filter 'www.google.com' '$host';
    proxy_pass http://www.google.com;
    include _proxy.inc;
    }
    }
    akira
        3
    akira  
       2014-07-02 10:11:08 +08:00
    是自己编译的nginx么, sub_filter装了么
    Goooogle
        4
    Goooogle  
       2014-07-02 17:20:47 +08:00
    @iCodex
    这种方式打开该域名后
    短时间内会无法连接相应域名
    ultimate010
        5
    ultimate010  
       2014-07-04 11:36:22 +08:00
    @danbao 给力,使用了.
    sadan9
        6
    sadan9  
    OP
       2014-07-04 17:56:56 +08:00
    subs_filter 不一定好用啊= =,有的时候会碰到google.co.jp google.com.sg之类的……
    Livid
        7
    Livid  
    MOD
    PRO
       2014-07-05 04:16:15 +08:00 via iPhone
    proxy_set_header Host www.google.com.hk;
    sadan9
        8
    sadan9  
    OP
       2014-07-05 04:53:40 +08:00
    server{
    listen 443;
    ssl on;
    server_name s.galdb.net;
    ssl_certificate /data/crt/s.galdb.net.crt;
    ssl_certificate_key /data/crt/s.galdb.net.key;
    location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Accept-Encoding "";
    proxy_pass http://www.google.com.hk;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Accept-Language "zh-CN";
    sub_filter www.google.com.hk s.galdb.net;
    sub_filter_once off;
    proxy_redirect off;
    proxy_set_header Host www.google.com.hk;
    }
    }


    用这个配置还是会被重新定向到www.google.com.hk = =
    feather12315
        9
    feather12315  
       2015-09-17 00:29:43 +08:00
    事情间隔那么久,我来填写答案吧。
    proxy_redirect https://www.google.com /;
    重定向到 /
    哎。被网上东西骗了好久
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1131 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 23:58 PVG 07:58 LAX 15:58 JFK 18:58
    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