向晚时光

记一次使用Nginx模块反代某国外搜索引擎

笔记 ·

今天(2018/5/22)发现域名被墙了,原因貌似是两个诺贝尔和平奖,先放个十天半个月看看会不会解吧。

这段时间闲着发慌,手里闲置了一个毛子的小鸡,恰巧那几天套路云的.cc域名促销20r/y,于是就想着要搞点什么事情。

对于反代Google的尝试之前我也做过很多,虚机+PHP源码,VPS+Zmirror一键脚本,后来维持不了多久就因各种各样的原因弃了。

这次折腾的方法是使用ngx_http_google_filter_module模块,老东西了,开发者也已经三年没有维护更新了,学术已经不能用了,只能实现简单的搜索功能。

反代过程就不细说了,网上一搜关键词多了去教程,具体我是参考这篇文章的:

一种非常方便 反向代理(镜像)Google 的 Nginx Google 扩展

贴一下我的Nginx配置:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
    upstream www.google.com {
        server 173.194.222.99:443 weight=1;
        server 173.194.222.100:443 weight=1;
        server 173.194.222.101:443 weight=1;
        server 173.194.222.102:443 weight=1;
        server 173.194.222.103:443 weight=1;
        server 173.194.222.104:443 weight=1;
        server 173.194.222.105:443 weight=1;
        server 173.194.222.106:443 weight=1;
        server 173.194.222.147:443 weight=1;
    }
    
    server { 
        listen 80;
        server_name findle.cc;
        # http 跳转 https
        location / {
              rewrite ^/(.*)$ https://findle.cc$1 permanent;
        }
    }
    

    server {
        listen       443 ssl;
        server_name  findle.cc;
        resolver 8.8.8.8;
            
        ssl on;
        ssl_certificate /xxx/yourssl.pem;
        ssl_certificate_key /xxx/yourssl.key;
        
        # 防止网络爬虫
        #forbid spider
        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_robots_allow on;
          #显示谷歌学术的验证码,但...
          subs_filter '"sitekey":"6LfFDwUTAAAAAIyC8IeC3aGLqVpvrB6ZpkfmAibj"'
                      '"sitekey":"6Lcujj0UAAAAAPS7NGeEcMQ5JbMrhjI2jfAj5PQr"' ir;
        }

}

以上,都不是重点,重点在这里:

https://findle.cc/

嘘~小众备用保平安。域名含义:Find=找,le=瞄了一眼桌上吃灰半年的kindle,可能纯属是为了顺口233

# note, nginx, proxy