Nginx反向代理Google扩展ngx_http_google_filter_module

模块介绍

ngx_http_google_filter_module是一个过滤器模块,能够让谷歌镜像更便捷的部署。内建了正则表达式、URI locations和其他复杂的配置。原生nginx模块确保了更加高效地处理cookies, gstatic scoures和重定向。

安装Nginx

使用《OneinStack》Nginx选择y,其余n

重新编译Nginx,安装ngx_http_google_filter_module模块

  1. cd /root/oneinstack/src
  2. git clone https://github.com/cuber/ngx_http_google_filter_module
  3. git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
  4. wget http://mirrors.linuxeye.com/oneinstack/src/pcre-8.39.tar.gz
  5. wget http://mirrors.linuxeye.com/oneinstack/src/openssl-1.0.2j.tar.gz
  6. tar xzf pcre-8.39.tar.gz
  7. tar xzf openssl-1.0.2j.tar.gz
  8. tar xzf nginx-1.10.2.tar.gz
  9. cd nginx-1.10.2
  10. ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module \
  11. --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module \
  12. --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2j \
  13. --with-pcre=../pcre-8.39 --with-pcre-jit --with-ld-opt='-ljemalloc' \
  14. --add-module=../ngx_http_google_filter_module \
  15. --add-module=../ngx_http_substitutions_filter_module
  16. make
  17. mv /usr/local/nginx/sbin/nginx{,_`date +%m%d`}  #备份现有nginx
  18. cp objs/nginx /usr/local/nginx/sbin/  #更新nginx
  19. nginx -t  #检查nginx语法
  20. service nginx restart

要正确使用ngx_http_google_filter_module模块,需要依赖扩展:

  • pcre 正则
  • ngx_http_proxy_module 反向代理
  • ngx_http_substitutions_filter_module 多重替换

安装Let's Encrypt

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

选择7安装Let's Encrypt,具体参考《OneinStack自动部署Let’s Encrypt证书

绑定域名

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

vhost.sh绑定域名(demo.linuxeye.com,请改成自己域名),ssl选择y,Let's Encrypt选择y,具体参考《OneinStack自动部署Let’s Encrypt证书

更改配置文件

  1. vi /usr/local/nginx/conf/vhost/demo.linuxeye.com.conf,保持内容如下:
  2. server {
  3. listen 443 ssl http2;
  4. server_name demo.linuxeye.com;
  5. ssl_certificate /usr/local/nginx/conf/ssl/demo.linuxeye.com.crt;
  6. ssl_certificate_key /usr/local/nginx/conf/ssl/demo.linuxeye.com.key;
  7. ssl_session_timeout 10m;
  8. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  9. ssl_prefer_server_ciphers on;
  10. ssl_ciphers CHACHA20:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
  11. ssl_session_cache builtin:1000 shared:SSL:10m;
  12. resolver 8.8.8.8 8.8.4.4 valid=300s;
  13. resolver_timeout 5s;
  14. location / {
  15. google on;
  16. google_scholar on;  #google_scholar 依赖于 google, 所以 google_scholar 无法独立使用。由于谷歌学术近日升级, 强制使用 https 协议, 并且 ncr 已经支持, 所以不再需要指定谷歌学术的 tld
  17. google_language en;  #语言偏好,默认使用 zh-CN (中文)
  18. }
  19. }

  20. server {
  21. listen 80;
  22. server_name demo.linuxeye.com;
  23. rewrite ^(.*)$ https://$host$1 permanent; #访问http跳转至https
  24. }

保持配置文件重启nginx:

  1. service nginx restart   
此文章转自 linux笔记
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值