当前位置: > Linux服务器 > nginx >

Nginx Google 扩展-ngx_http_google_filter_module

时间:2016-04-11 22:10来源:linux.it.net.cn 作者:IT
下载Nginx Google扩展





1
git clone https://github.com/cuber/ngx_http_<a href="https://www.olinux.org.cn/tag/google" title="查看与 google 相关的文章"target="_blank">google</a>_filter_module

下载 substitutions扩展





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

编译nginx选项增加





1
--add-module=../ngx_http_<a href="https://www.olinux.org.cn/tag/google" title="查看与 google 相关的文章"target="_blank">google</a>_filter_module --add-module=../ngx_http_substitutions_filter_module

基本配置方法

http>配置方式





01
server { server_name<你的域名>; 



02
listen 80; 



03
resolver 8.8.8.8; 



04
location / {



05
google on; 



06
}



07
}



08
https配置方式



09
server {



10
  server_name <你的域名>;



11
  listen 443;



12
  ssl on;



13
  ssl_certificate <你的证书>;



14
  ssl_certificate_key <你的私钥>;



15
  resolver 8.8.8.8;



16
  location / {



17
    google on;



18
  }



19
}

进阶配置方法

基本搜索

需要配置 resolver用于域名解析





1
server { # ... 仅列举部分配置 



2
resolver 8.8.8.8; 



3
location / { 



4
google on; 



5
} # ... 



6
}

谷歌学术

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





1
location / { 



2
google on; 



3
google_scholar on; 



4
}

默认语言偏好

默认的语言偏好可用 google_language 来设置, 如果没有设置, 默认使用zh-CN (中文)





1
location / { 



2
google on; 



3
google_scholar on; # 设置成德文google_language "de"; 



4
}

支持的语言如下.
ar    -> 阿拉伯
bg    -> 保加利亚
ca    -> 加泰罗尼亚
zh-CN -> 中国 (简体)
zh-TW -> 中国 (繁体)
hr    -> 克罗地亚
cs    -> 捷克
da    -> 丹麦
nl    -> 荷兰
en    -> 英语
tl    -> 菲律宾
fi    -> 芬兰
fr    -> 法国
de    -> 德国
el    -> 希腊
iw    -> 希伯来
hi    -> 印地文
hu    -> 匈牙利
id    -> 印度尼西亚
it    -> 意大利
ja    -> 日本
ko    -> 朝鲜
lv    -> 拉脱维亚
lt    -> 立陶宛
no    -> 挪威
fa    -> 波斯
pl    -> 波兰
pt-BR -> 葡萄牙 (巴西)
pt-PT -> 葡萄牙 (葡萄牙)
ro    -> 罗马尼亚
ru    -> 俄罗斯
sr    -> 塞尔维亚
sk    -> 斯洛伐克
sl    -> 斯洛文尼亚
es    -> 西班牙
sv    -> 瑞典
th    -> 泰国
tr    -> 土耳其
uk    -> 乌克兰
vi    -> 越南


搜索引擎爬虫许可

任何搜索引擎爬虫都不被允许爬取 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;
}

Proxy Protocal

默认采用 https 与后端服务器通信.
你可以使用 google_ssl_off 来强制将一些域降到 http 协议.
这个设置可以让一些需要二次转发的域通过 http 协议进行转发, 从而不再依赖 ssl 证书.

#
# 例如 'www.google.com' 按如下方式代理
# vps(hk) -> vps(us) -> google
#

#
# vps(hk) 配置
#
server {
  # ...
  location / {
    google on;
    google_ssl_off "www.google.com";
  }
  # ...
}

upstream www.google.com {
  server < vps(us) 的 ip >:80;
}

#
# vps(us) 配置
#
server {
  listen 80;
  server_name www.google.com;
  # ...
  location / {
    proxy_pass https://www.google.com;
  }
  # ...
}
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容