很简单只需要在nginx.conf中加入下面几行或者新建一个文件再include进nginx.conf中即可。 每一行我会写入注释帮助理解。这里感谢伟大的互联网. 说明下面的codewalker.me 为代理服务器域名配置时设置为自己的任意公网可访问域名

#配置代理的缓存
#keys_zone后面的GPC是名字后面要调用.
proxy_cache_path /tmp/google_proxy_cache/one levels=1:2 keys_zone=GPC:10m max_size=2g;
proxy_cache_key “$host$request_uri”;

upstream google.agent {
#下面的IP地址是通过nslookup获得。
#多写点用于轮训
#1 代理方式有三种默认不写就是轮训
#2 ip_hash
#3 url_hash
#很好理解就是字面意思, ip哈希, URL哈希.
server 74.125.239.116:80 max_fails=3;
server 74.125.239.115:80 max_fails=3;
server 74.125.239.112:80 max_fails=3;
server 74.125.239.113:80 max_fails=3;
server 74.125.239.114:80 max_fails=3;
server 74.125.224.80:80 max_fails=3;
server 74.125.224.81:80 max_fails=3;
server 74.125.224.82:80 max_fails=3;
server 74.125.224.83:80 max_fails=3;
server 74.125.224.84:80 max_fails=3;
}
server {
listen 80;
server_name codewalker.me; #配置的时候是通过这个域名访问然后反向代理到上面的server列表中去.
location / {
proxy_cache GPC;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 404 1m;
#很重要,把连接中的google链接换成代理服务器的域名这里也就是codewalker.me
#不然就要直接访问Google所以跳转一下
proxy_redirect https://www.google.com/ /;
#设置cookie
proxy_cookie_domain google.com codewalker.me;
proxy_pass http://google.agent;#使用最上面的servers.
proxy_set_header Host “www.google.com“;
proxy_set_header Accept-Encoding “”;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Accept-Language “zh-CN”;
#设置cookie很重要不然你就等着输验证码吧
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”;
#超级重要啊!这里你的nginx必须安装有http_sub_module模块
#编译安装的时候–with-http_sub_module
sub_filter www.google.com codewalker.me;
sub_filter_once off;
}
}

题外话 其实这就是Nginx的反向代理可用于负载均衡。 也就是你的主域名解析到这个server上。通过这个server再分发到其他servers. 打完收工 EOF