什么是Google Filter
ngx_http_google_filter_module是一个过滤模块,模块已经内置了正则表达式,URI位置和其他复杂配置。模块可确保效率的处理cookie,gstatic scoures和redirections等。
如何使用Google Filter
安装编译环境
yum -y install gcc gcc-c++ git
安装Nginx依赖
yum -y install pcre-devel openssl-devel zlib-devel
下载过滤模块
git clone https://github.com/cuber/ngx_http_google_filter_module
下载替换模块
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
配置编译选项及安装
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module
修改配置应用模块
server {
server_name localhost;
listen 80;
resolver 8.8.8.8;
location / {
google on;
}
}
访问测试
直接使用浏览器访问Nginx中配置的server_name即可
相关设置
# 谷歌学术
location / {
google_scholar on;
}
# 谷歌语言
location / {
google_language en;
}
ar -> Arabic
bg -> Bulgarian
ca -> Catalan
zh-CN -> Chinese (Simplified)
zh-TW -> Chinese (Traditional)
hr -> Croatian
cs -> Czech
da -> Danish
nl -> Dutch
en -> English
tl -> Filipino
fi -> Finnish
fr -> French
de -> German
el -> Greek
iw -> Hebrew
hi -> Hindi
hu -> Hungarian
id -> Indonesian
it -> Italian
ja -> Japanese
ko -> Korean
lv -> Latvian
lt -> Lithuanian
no -> Norwegian
fa -> Persian
pl -> Polish
pt-BR -> Portuguese (Brazil)
pt-PT -> Portuguese (Portugal)
ro -> Romanian
ru -> Russian
sr -> Serbian
sk -> Slovak
sl -> Slovenian
es -> Spanish
sv -> Swedish
th -> Thai
tr -> Turkish
uk -> Ukrainian
vi -> Vietnamese
# 不允许搜索引擎爬取
location / {
google_robots_allow off;
}