返回顶部

收藏

nginx反向代理google

更多

天朝的墙弄得我不要不要的。

流量只进不出,想要查点好的资料,还是得Google,加上本人是google粉,所以没有FQ是不行的

开始用的goagent不过貌似google的ip被封了不少,然后放弃了

接着是红杏,开始很好用,然后买了一年,妈蛋。结果也被搞掉了,到现在还没恢复

然后就是自己搞vps,现在访问的挺爽。

独乐了不如众乐乐,我用自己的vps做一个反向代理来给大家带来点福音,哈哈,闲话少说,开搞!

用的是nginx一个开源的扩展,下面是github地址

https://github.com/cuber/ngx_http_google_filter_module.git

一、安装Nginx,推荐用最新版

#安装依赖,以及git
yum -y install gcc openssl-devel pcre-devel zlib-devel libtool gcc-c++ build-essential git make

# 下载最新版源码
# nginx 官网: 
# http://nginx.org/en/download.html
#
wget "http://nginx.org/download/nginx-1.7.8.tar.gz"

#
# 下载最新版 pcre
# pcre 官网:
# http://www.pcre.org/
#
wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz"

#
# 下载最新版 openssl
# opessl 官网:
# https://www.openssl.org/
#
wget "https://www.openssl.org/source/openssl-1.0.1j.tar.gz"

#
# 下载最新版 zlib
# zlib 官网:
# http://www.zlib.net/
#
wget "http://zlib.net/zlib-1.2.8.tar.gz"

#
# 下载扩展
#
git clone https://github.com/cuber/ngx_http_google_filter_module

#
# 下载 substitutions 扩展
#
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

#
# 解压缩
#
tar xzvf nginx-1.7.8.tar.gz
tar xzvf pcre-8.36.tar.gz
tar xzvf openssl-1.0.1j.tar.gz
tar xzvf zlib-1.2.8.tar.gz

#
# 进入 nginx 源码目录
#
cd nginx-1.7.8

#
# 设置编译选项
#

./configure \
"--prefix=/export/servers/nginx"     "--sbin-path=/export/servers/nginx/sbin/nginx"  \
"--conf-path=/export/servers/nginx/conf/nginx.conf"   \
"--error-log-path=/export/servers/nginx/logs/error.log"   \
"--http-log-path=/export/servers/nginx/logs/access.log"   \
"--pid-path=/export/servers/nginx/var/nginx.pid"   \
"--lock-path=/export/servers/nginx/var/nginx.lock"   \
"--http-client-body-temp-path=/dev/shm/nginx_temp/client_body"   \
"--http-proxy-temp-path=/dev/shm/nginx_temp/proxy"   \
"--http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi"  \
"--user=admin"     "--group=admin"     "--with-cpu-opt=pentium4F"  \
"--without-select_module"     "--without-poll_module"     "--with-http_realip_module"   \
"--with-http_sub_module"     "--with-http_gzip_static_module"     "--with-http_stub_status_module"  \
"--without-http_ssi_module"     "--without-http_userid_module"    \
"--without-http_ssi_module"     "--without-http_userid_module"    \
"--without-http_geo_module"     "--without-http_map_module"     "--without-mail_pop3_module"   \
"--without-mail_imap_module"     "--without-mail_smtp_module" \
 --with-pcre=../pcre-8.36 \
  --with-openssl=../openssl-1.0.1j \
  --with-zlib=../zlib-1.2.8 \
  --with-http_ssl_module \
  --add-module=../ngx_http_google_filter_module \
  --add-module=../ngx_http_substitutions_filter_module \

# 编译安装
make -j 64 && make -j 64 install

# 启动
/export/servers/nginx/sbin/nginx -s restart

安装完成,开始配置反向代理

基于扩展的基本http配置

server {
  server_name <你的域名>;
  listen 80;

  resolver 8.8.8.8;
  location / {
    google on;
  }
}

https配置

server {
  server_name <你的域名>;
  listen 443;

  ssl on;
  ssl_certificate <你的证书>;
  ssl_certificate_key <你的私钥>;

  resolver 8.8.8.8;
  location / {
    google on;
  }
}

本人的ngixn反向代理配置

server {
  listen 80;
  server_name              www.overloader.cn;
  access_log               /export/servers/nginx/logs/www.overloader.cn/www.overloader.cn_access.log main;
  error_log                /export/servers/nginx/logs/www.overloader.cn/www.overloader.cn_error.log warn;
  # ...
  resolver 8.8.8.8;
  location / {
   # proxy_pass https://www.overloader.cn/;
    google on;
    google_ssl_off "www.google.com"
    google_scholar on;
    google_language zh-CN;
  }
  # ...
}

放弃nginx google第三方扩展,改用google 全球ip做负载均衡

upstream www.overloader.cn {
#    server 173.194.38.1:443 weight=10 max_fails=2 fail_timeout=30s;
#    server 173.194.38.2:443 weight=10 max_fails=2 fail_timeout=30s;
#    server 173.194.38.3:443 weight=10 max_fails=2 fail_timeout=30s;
#    server 173.194.38.4:443 weight=10 max_fails=2 fail_timeout=30s;
#    server 74.125.239.112:443 weight=10 max_fails=2 fail_timeout=30s;
    server 74.125.239.144:443 weight=10 max_fails=2 fail_timeout=30s;
    server 74.125.239.114:443 weight=10 max_fails=2 fail_timeout=30s;
    server 74.125.239.115:443 weight=10 max_fails=2 fail_timeout=30s;
    server 74.125.239.116:443 weight=10 max_fails=2 fail_timeout=30s;
    server 216.58.220.132:443 weight=10 max_fails=3 fail_timeout=10s;
    server 131.203.2.49:443 weight=10 max_fails=3 fail_timeout=10s;
    server 216.58.209.165:443 weight=10 max_fails=3 fail_timeout=10s;
#    server 209.85.229.53:443 weight=10 max_fails=3 fail_timeout=10s;
    server 173.194.122.22:443 weight=10 max_fails=3 fail_timeout=10s;
    server 216.58.209.101:443 weight=10 max_fails=3 fail_timeout=10s;
    server 173.194.126.65:443 weight=10 max_fails=3 fail_timeout=10s;
}
server {
  listen      80;
  server_name     www.overloader.cn overloader.cn;
  return      301 https://$server_name$request_uri;
}
server {
  listen                    443;
  ssl                       on;
  server_name               www.overloader.cn overloader.cn;
  ssl_certificate           crt;
  ssl_certificate_key       key;
  ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers               RC4:HIGH:!aNULL:!MD5;
  ssl_session_timeout       10m;
  ssl_session_cache         shared:SSL:1m;
  ssl_prefer_server_ciphers on;
  access_log               www.overloader.cn_access.log main;
  error_log                www.overloader.cn_error.log warn;
  # ...
  resolver                 8.8.8.8;
  location / {
    proxy_pass https://www.overloader.cn;
    proxy_cookie_domain google.com www.overloader.cn;
    proxy_set_header Host "www.google.com";
    proxy_ignore_headers Expires Vary Cache-Control X-Accel-Expires;
    proxy_set_header If-Modified-Since "";
    proxy_set_header X=Real-IP $remote_addr;
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header referer "http://www.overloader.cn$request_uri";
    proxy_set_header Accept-Encoding "";
    proxy_cache  google_cache;
    proxy_cache_valid 200 304 1d;
    proxy_cache_key $host$uri$is_args$args;
    subs_filter www.google.com www.overloader.cn gi;
    subs_filter \"google.com\" \"overloader.cn\";
    subs_filter \'google.com\' \'overloader.cn\';
    header_filter_by_lua 'ngx.header["Content-Encoding"]=""';
  }
}

以下是访问结果

插入图片

标签:nginx,google,反向代理

收藏

0人收藏

支持

3

反对

0

相关聚客文章
  1. David Huang 发表 2014-09-06 11:14:36 自己反代Google字体库,实现国内/外均高速访问
  2. 博主 发表 2014-12-18 16:00:00 Nginx 反向代理 Google
  3. 銏文坺 发表 2014-09-01 12:55:29 使用Apache2搭建Google加密反向代理
  4. Li Xi 发表 2014-08-08 10:09:03 PHP整合Nginx反向代理的用法
  5. David Huang 发表 2015-06-07 04:54:46 修好了secure.hjc.im
  6. cold 发表 2012-02-09 09:35:00 nginx+keepalived配置高可用HTTP群集
  7. furion 发表 2016-01-27 12:37:28 nginx+lua+redis实现反向代理
  8. welpher 发表 2012-07-25 12:47:00 wordpress/nginx安全设置
  9. 和大头 发表 2011-06-23 12:52:35 《构建高性能Web站点》学习笔记
  10. crazyFish 发表 2011-12-14 14:35:20 nginx负载均衡和方向代理
  11. cold 发表 2012-02-09 09:35:00 nginx+keepalived配置高可用HTTP群集
  12. crazyFish 发表 2011-12-14 14:35:20 nginx负载均衡和方向代理

发表评论