使用Nginx反向代理google,做谷歌搜索镜像
起步
梯子有点慢。如果用VPS直接转发给谷歌,应该会快一些。实验结果也确实是如此,尽管我用的是同一个服务器。
代理设置
Nginx 需要支持 sub_module ,也就是编译时有 --with-http_sub_module 。我是系统安装的ng 1.12.2 ,默认就有使用该模块了,我也就不用重新编译了。
proxy_cache_path /tmp levels=1:2 keys_zone=cache:10m max_size=10g inactive=60m use_temp_path=off;
server {
listen 80;
server_name <yourdomain>;
location / {
proxy_redirect off;
proxy_cache cache;
proxy_cache_valid 200 304 12h;
proxy_cache_valid any 10m;
proxy_cookie_domain google.com <yourdomain>;
proxy_pass https://www.google.com;
proxy_connect_timeout 20s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_set_header Host "www.google.com";
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Referer https://www.google.com;
proxy_set_header Accept-Encoding "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
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";
sub_filter https://www.google.com.hk http://<yourdomain>;
sub_filter https://www.google.com http://<yourdomain>;
sub_filter_once off;
addition_types *;
}
}配置项的说明:
- proxy_redirect:默认会302重定向到谷歌地址,所以要设置 off;
- proxy_cache:设置代理缓存,加快访问速度;
- proxy_pass:设置起到反向代理作用的配置;
- proxy_set_header:设置请求体头部,特别是 Cookie 那段,防止谷歌即时搜索, NW=1 表示搜索结果新窗口打开,也比较符合国人习惯; Accept-Encoding 防止谷歌返回压缩的内容,因为压缩的内容无法做域名替换;
- sub_filter:字符串替换。
启用 Nginx 认证(可选)
如果您不希望任何人都可以访问您的网站,也是为了防止域名被封啊。
那么需要启用 Nginx 认证,仅登录成功后才可访问该网站。
生成密码文件:
# mkdir /etc/nginx/conf/auth
# htpasswd -b -c -m /etc/nginx/conf/auth/htpasswd weapon xxxxxx在ng配置中:
auth_basic "login";
auth_basic_user_file /usr/local/nginx/conf/auth/htpasswd;
location / {
...
}这样就是登录后才能访问站点了。
原文 http://www.hongweipeng.com/index.php/archives/1883/
本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!