Google Scholar代理搭建笔记

2018年5月8日 科学上网 1条评论 阅读次数 1,261

VPS和系统

作为示范,这选择 VPSao 的96M VPS主机作为示范。一来便宜3.5$一年,二来96M足够跑Nginx和BBR(OVZ)了。如果经济条件允许,请购买更高等级的VPS。

系统这里选择(ubuntu 16.04 x86-64),没选centos原因是,那得写两篇笔记。

需求

Nginx

这里Nginx选择的是最新版本(1.14.0)

域名

由于需要开启https,所以需要申请一个域名,可以去dot.tk申请,这里申请到的域名为: show-scholar.tk

申请google Recaptcha

这是为了解决google验证码问题,申请地址(这里需要一个梯子)

编译nginx

编译带ngx_http_google_filter_module模块的nginx。

清理ubuntu没用的软件

rm -rf /var/www
apt purge -y apache* postfix* xinet*
apt update
apt upgrade

编译需要的软件

apt install -y build-essential git gcc g++ make

需要的源码

wget "http://nginx.org/download/nginx-1.14.0.tar.gz"
wget "https://www.openssl.org/source/openssl-1.0.2o.tar.gz"
wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz"
wget "http://www.zlib.net/zlib-1.2.11.tar.gz"
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
tar zxvf zlib-1.2.11.tar.gz
tar zxvf nginx-1.14.0.tar.gz
tar zxvf pcre-8.42.tar.gz
tar zxvf openssl-1.0.2o.tar.gz

配置nginx

cd nginx-1.14.0
./configure                        \
    --prefix=/etc/nginx            \
    --with-http_stub_status_module \
    --with-http_ssl_module         \
    --with-http_gunzip_module      \
    --with-http_gzip_static_module \
    --with-stream                  \
    --with-stream_ssl_module       \
    --with-threads                 \
    --with-pcre=../pcre-8.42       \
    --with-zlib=../zlib-1.2.11     \
    --with-openssl=../openssl-1.0.2o \
    --add-module=../ngx_http_google_filter_module \
    --add-module=../ngx_http_substitutions_filter_module\
    --user=www-data \
    --group=www-data

执行结果

creating objs/Makefile

Configuration summary
  + using threads
  + using PCRE library: ../pcre-8.42
  + using OpenSSL library: ../openssl-1.0.2o
  + using zlib library: ../zlib-1.2.11

  nginx path prefix: "/etc/nginx"
  nginx binary file: "/etc/nginx/sbin/nginx"
  nginx modules path: "/etc/nginx/modules"
  nginx configuration prefix: "/etc/nginx/conf"
  nginx configuration file: "/etc/nginx/conf/nginx.conf"
  nginx pid file: "/etc/nginx/logs/nginx.pid"
  nginx error log file: "/etc/nginx/logs/error.log"
  nginx http access log file: "/etc/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

编译和安装NGINX

make && make install
cp /etc/nginx/sbin/nginx /usr/sbin/nginx
nginx

打开网页

如果能打开网页说明已经可以工作了

配置nginx

更改 servername

将 /etc/nginx/conf/nginx.conf 中的

server_name  localhost; 改为 server_name show-scholar.tk;
nginx -s reload

生成SSL证书

mkdir /etc/nginx/ssl
apt install -y socat curl
curl https://get.acme.sh | sh
source ~/.bashrc

acme.sh  --issue -d show-scholar.tk  --webroot  /etc/nginx/html

recaptcha

填入你的名字和domain网址
申请 reCAPTCHA v2
得到一组* Site key _和_ Secret key *
这里申请的到的site key:6LeP9VcUAAAAAOEdpMfibSgLvqKyCBzz6n_sDl-f
sercret key(保密)
6LeP9VcUAAAAAHsZx6Mrgn4kC1sEvFHTjy9jru-o

开启代理模块配置

复制到/etc/nginx/conf/nginx.conf中

user    www-data;
worker_processes  1;

error_log  logs/error.log;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include            mime.types;
    default_type       application/octet-stream;
    sendfile           on;
    keepalive_timeout  65;

    server {
        listen               443;
        server_name          show-scholar.tk;
        ssl                  on;
        ssl_certificate      /root/.acme.sh/show-scholar.tk/fullchain.cer;
        ssl_certificate_key  /root/.acme.sh/show-scholar.tk/show-scholar.tk.key;
        ssl_ciphers          EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
        add_header           Strict-Transport-Security max-age=15768000;
        gzip                 on;
        gzip_comp_level      6;
        gzip_proxied         any;
        gzip_types           gzip_types text/plain application/x-javascript text/css text/javascript image/gif;
        resolver 8.8.8.8;
        location / {
            google on;
            google_scholar on;
            subs_filter '6LeP9VcUAAAAAOEdpMfibSgLvqKyCBzz6n_sDl-f'
            '6LeP9VcUAAAAAHsZx6Mrgn4kC1sEvFHTjy9jru-o' ir;
              #前一个从网页获得,后一个是site-key
        }
        location ~ ^/ipv4/sorry/ {
            google on;

            subs_filter '6LeP9VcUAAAAAOEdpMfibSgLvqKyCBzz6n_sDl-f'
            '6LeP9VcUAAAAAHsZx6Mrgn4kC1sEvFHTjy9jru-o' ir;

            subs_filter '(<img src="/sorry/image.*continue=https://)show-scholar.tk'
            '1www.google.com' ir;              subs_filter '(1www.google.com' ir;
        }
    }
    server {
        listen       80;
        return       301     https://show-scholar.tk$request_uri;
    }
}

安装BBR(OVZ)加速

在控制面板(Solusvm)中开启 TUN/TAP

wget --no-check-certificate https://raw.githubusercontent.com/sjzMa/shell-scripts/master/ovz-bbr/ovz-bbr-installer.sh
chmod +x ovz-bbr-installer.sh
./ovz-bbr-installer.sh

加入443端口 加速

#修改代理端口:
vi  /usr/local/haproxy-lkl/etc/port-rules
#一行一个
systemctl restart haproxy-lkl

访问学术

https://show-scholar.tk/scholar 即可