我的环境是 Centos7 x64 3.10.0-123.8.1.el7.x86_64
服务器环境是 LTANMP 一键安装包部署 移步

下面给出Tengie/Nginx的配置文件

proxy_cache_path  /data/nginx/cache/one  levels=1:2   keys_zone=one:10m max_size=10g;
proxy_cache_key  "$host$request_uri";
server {
listen 80;
server_name g.haobingo.com;
rewrite ^(.*) https://g.haobingo.com$1 permanent;
}
 
upstream google {
 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      443;
        server_name  g.haobingo.com;
         ssl on;
    ssl_certificate /usr/local/nginx/g.haobingo.com.crt;
    ssl_certificate_key /usr/local/nginx/g.haobingo.com.key;
location / {
                proxy_cache one;
                proxy_cache_valid  200 302  1h;
                proxy_cache_valid  404      1m;
                proxy_redirect https://www.google.com/ /;
                proxy_cookie_domain google.com g.haobingo.com;
                proxy_pass              http://google;
                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";
                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 www.google.com g.haobingo.com;
                sub_filter_once off;
}
}

我使用了SSL证书,可以自行申请,我使用的是沃通免费证书,传送门
需要注意的是 sub_filter 这个模块可能需要安装,我使用的那个一键安装包没有编译进去,需要重新编译Tengie/Nginx,编译方法如下:
打开LTANMP一键安装包目录,进入Tengie,我的目录是 /home/ltanmp/tengine-2.1.0

cd /home/ltanmp/tengine-2.1.0
./configure --prefix= --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sysguard_module --with-http_concat_module --with-http_upstream_check_module --with-google_perftools_module --with-http_sub_module
make

执行完之后

mkdir -p /data/nginx/cache
touch /data/nginx/cache/one
/etc/init.d/nginx stop
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp objs/nginx /usr/local/nginx/sbin/
/etc/init.d/nginx start

然后就可以了

参考:

https://www.centos.bz/2014/06/nginx-proxy-google/
http://rmingwang.com/install-nginx-third-modules-http_sub_module.html

标签:google, 代理, tengine, nginx

添加新评论