您尚未登录。

#1 2020-08-06 22:38:18

caizhengzhu
管理员

Nginx 反代 Google

https://zvv.me/z/1783.html

以下配置,只需将其中的中文关键词替换为你自己的之后,就可以直接使用了。

### server 段 ###
server {
        listen 监听端口;

        server_name 你的域名;

        # 为了安全考虑(例如 IP 被墙),强烈建议使用 HTTPS
        ssl on;
        ssl_protocols TLSv1.2;
        ssl_certificate ~/站点证书
        ssl_certificate_key ~/站点证书密钥

        location / {
            proxy_pass                          https://www.google.com;

            # 替换指定字符串
            sub_filter                          www.google.com 你的域名;
            # 字符串只进行一次替换,即只替换第一个被匹配的字符串。这里关闭。
            sub_filter_once                     off;

            # 指定头部:
            proxy_set_header  Host              "www.google.com";
            proxy_set_header  Referer           $http_referer;
            proxy_set_header  X-Real-IP         $remote_addr;
            proxy_set_header  User-Agent        $http_user_agent;
            # 防止谷歌返回压缩的内容,因为压缩的内容无法替换字符串
            proxy_set_header  Accept-Encoding   "";

            #把 cookie 的作用域替换成你的域名
            proxy_cookie_domain                 www.google.com 你的域名;
            #传固定的 cookie 给谷歌,是为了禁止即时搜索,因为开启即时搜索无法替换内容
            proxy_set_header  Cookie            "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=en-US:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
        }
}

然后重新加载你的 Nginx,就可以访问你的域名看看效果了。

离线

在此主题中在线的注册用户:0, 访客:1
[Bot] ClaudeBot

论坛底部