Nginx代理Google

Nginx代理Google

下载

1.oneinstack

wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz

安装oneinstack

1
2
tar xzf oneinstack-full.tar.gz
cd oneinstack

下载Nginx所需模块

1
2
3
cd oneinstack/src
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

如果nginx版本为1.14+,ngx_http_google_filter_module 需要切换至dev分支、详见issue

编译安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
cd ~/oneinstack
# 修改 option.conf 中的 nginx_modules

vim ~/oneinstack/option.conf

#如下
# Add modules
nginx_modules_options='--add-module=/root/oneinstack/src/ngx_http_google_filter_module --add-module=/root/oneinstack/src/ngx_http_substitutions_filter_module'

#安装Nginx
./install
#可以只装nginx

添加虚拟主机

1
2
cd /root/oneinstack
./vhost.sh



修改配置文件

1
vim /usr/local/nginx/conf/vhost/demo.happyhack.cn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/nginx/conf/ssl/demo.happyhack.cn.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/demo.happyhack.cn.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name demo.happyhack.cn;
access_log off;
#index index.html index.htm index.php;
#root /data/wwwroot/demo.happyhack.cn;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

include /usr/local/nginx/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
{
return 403;
}
location / {
google on;
google_scholar on;
google_language zh-CN; #zh-CN
#google_language en; #zh-CN
}
}

重启Nginx服务器Bingo!哈哈😄

参考链接

oneinstak