Nginx搭建Google代理查询服务
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx搭建Google代理查询服务相关的知识,希望对你有一定的参考价值。
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
查看已安装的模块,需要重新编译安装
[[email protected] 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 证书
[[email protected] conf]$ #cd /usr/local/nginx/conf
[[email protected] conf]$ #openssl genrsa -des3 -out server.key 1024
[[email protected] conf]$ #openssl req -new -key server.key -out server.csr
[[email protected] conf]$ #openssl rsa -in server.key -out server_nopwd.key
[[email protected] 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代理查询服务的主要内容,如果未能解决你的问题,请参考以下文章