码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx搭建Google代理查询服务

时间:2016-10-20 07:42:05      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

VPS机器环境 : CenterOS 6.0

LNMP 1.2 编译安装包,且已安装

 

下载安装ngx_http_substitutions_filter_module模块

 

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

下载安装ngx_cache_purge 模块

 

wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz

tar xzf ngx_cache_purge-2.1.tar.gz

 

查看已安装的模块,需要重新编译安装

 

[root@vultr nginx-1.8.0]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.8.0

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

 

configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module

 

进入lump1.2-full/src/nginx 1.8.0目录下,配置

 

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/install/ngx_http_substitutions_filter_module -add-module=/install/ngx_cache_purge-2.1

 

编译

 

make

 

只替换生成的执行文件

 

cp objs/nginx /usr/local/nginx/sbin/nginx

 

 

2. 创建 ssl 证书

 

[ysisl@vultr conf]$ #cd /usr/local/nginx/conf

[ysisl@vultr conf]$ #openssl genrsa -des3 -out server.key 1024

[ysisl@vultr conf]$ #openssl req -new -key server.key -out server.csr

[ysisl@vultr conf]$ #openssl rsa -in server.key -out server_nopwd.key

[ysisl@vultr conf]$ #openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt

 

 

 

3. 在nginx/conf/vhost目录下,创建google.conf 

 

 

upstream google {

        server 173.194.38.191:80 max_fails=3;

        server 173.194.38.192:80 max_fails=3;

        server 173.194.38.193:80 max_fails=3;

        server 173.194.38.194:80 max_fails=3;

}

 

server {

                listen 80;

                server_name g.ysisl.com;

                index index.html index.htm index.php;

                root  /u01/web/blog;

                rewrite ^/(.*) https://g.ysisl.com$1 last;

        }

 

server

    {

        listen 443;

        ssl on;

        ssl_certificate  /usr/local/nginx/conf/server.crt;

        ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;

        #listen 80;

        #listen [::]:80;

        server_name g.ysisl.com;

        location / {

#                proxy_cache one;

#               proxy_cache_valid  200 302 1h;

 #              proxy_cache_valid  404 1m;

                proxy_redirect https://www.google.co.jp/ https://g.ysisl.com/;

                proxy_cookie_domain google.co.jp g.ysisl.com;

                proxy_pass http://google;

                proxy_set_header Host "www.google.co.jp";

                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.co.jp g.ysisl.com ;

                sub_filter_once off;

            }

 

        access_log  /usr/local/nginx/logs/access_google.log  access;

    }

~        

 

 

4. 重启nginx 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Nginx搭建Google代理查询服务

标签:

原文地址:http://www.cnblogs.com/ysisl/p/5979323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!