一、准备工作

1、安装开发工具及依赖包:

apt update && apt -y install git gcc gcc-c++ make libpcre3-dev zlib1g-dev libssl-dev libxml2-dev libxslt1-dev libgd-dev libgeoip-dev

2、查看 Nginx 版本并在官网下载对应源码包:

nginx -V

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvzf nginx-1.18.0.tar.gz

3、下载 ngx_http_google_filter_module 和 ngx_http_substitutions_filter_module:

cd nginx-1.18.0
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

4、更换 ngx_http_google_filter_module 分支(不然会报错:nginx: [emerg] unknown directive "google" in):

cd ngx_http_google_filter_module
git checkout 77532b9

二、重新编译配置 Nginx

1、重新编译 Nginx:

./configure --with-cc-opt='...' --add-module=./ngx_http_google_filter_module --add-module=./ngx_http_substitutions_filter_module

make

编译后的 Nginx 二进制文件在 objs 目录下,复制到 /usr/sbin 覆盖即可

2、Nginx 反代 Google:

nano /etc/nginx/conf.d/google.conf

upstream www.google.com {
    server 172.217.1.4:443;
    server 172.217.4.36:443;
}

server {
    listen 80;
    listen [::]:80;
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;
    server_name domain.com;
    ssl_certificate /fullchain.cer;
    ssl_certificate_key /domain.com.key;
    resolver 8.8.8.8;

    location / {
        google on;
        google_scholar on; # Google 学术
        google_robots_allow on;
        google_language "zh-CN";
    }
}

最后重启 Nginx:systemctl restart nginx

Last modification:July 15th, 2020 at 02:36 pm
如果觉得我的文章对你有用,请随意赞赏