Stay Hungry, Stay Foolish

vps使用Nginx Google 扩展反向代理Google

Nginx Google 扩展

依赖库

  1. pcre 正则
  2. ngx_http_proxy_module 反向代理
  3. ngx_http_substitutions_filter_module 多重替换

安装

以 ubuntu 14.04 为例 i386, x86_64 均适用

最简安装
#
# 安装 gcc & git
#
apt-get install build-essential git gcc g++ 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.38.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.38.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=/opt/nginx-1.7.8 \
  --with-pcre=../pcre-8.38 \
  --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
  
#
# 编译, 安装
# 如果扩展有报错, 请发 issue 到
# https://github.com/cuber/ngx_http_google_filter_module/issues
#
make
sudo make install

#
# 启动, 安装过程到此结束
#
sudo /opt/nginx-1.7.8/sbin/nginx

#
# 配置修改后, 需要 reload nginx 来让配置生效, 
#
sudo /opt/nginx-1.7.8/sbin/nginx -s reload

基本配置方法

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;
  }
}
谷歌学术

google_scholar 依赖于 google, 所以 google_scholar 无法独立使用.
由于谷歌学术近日升级, 强制使用 https 协议, 并且 ncr 已经支持, 所以不再需要指定谷歌学术的 tld
配置 nginx

location / {
  google on;
  google_scholar on;
}
搜索引擎爬虫许可

任何搜索引擎爬虫都不被允许爬取 google 镜像
如下的默认 robots.txt 已经内置.

User-agent: *
Disallow: /

如果想要使用 google 自己的 robots.txt 请将 google_robots_allow 设为 on

  #...
  location / {
    google on;
    google_robots_allow on;
  }
  #...
Upstreaming

upstream 减少一次域名解析的开销, 并且通过配置多个网段的 google ip 能够一定程度上减少被 google 机器人识别程序侦测到的几率 (弹验证码).

# 可以通过如下方法获取 google ip
➜  ~  dig www.google.com @8.8.8.8 +short
173.194.38.209
173.194.38.211
173.194.38.212
173.194.38.210
173.194.38.208

然后将获取到的 ip 配置如下即可

upstream www.google.com {
  server 173.194.38.209:443;
  server 173.194.38.211:443;
  server 173.194.38.212:443;
  server 173.194.38.210:443;
  server 173.194.38.208:443;
}

详细参考:ngx_http_google_filter_module

喜欢 (0)
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦


Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in C:\inetpub\wordpress\wp-content\themes\XHBlog\comments.php on line 17
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址