Nginx Google反向代理扩展ngx_http_google_filter_module

Nginx Google反向代理扩展模块ngx_http_google_filter_module

ngx_http_google_filter_module扩展模块介绍

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

轻松部署

1、依赖库

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


下载substitutions扩展:
https://github.com/yaoweibin/ngx_http_substitutions_filter_module

2、依赖库安装过程(略)

3、Nginx重新编译安装

#cd /opt/lnmp1.2-full/src/nginx-1.8.0/

#./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module \
--with-http_gzip_static_module --with-ipv6 --with-http_sub_module \
--add-module=/opt/ngx_http_google_filter_module \
--add-module=/opt/ngx_http_substitutions_filter_module-master

#make && make install

#cp -rf objs/nginx /usr/sbin/nginx  (覆盖二进制文件)

#service nginx restart
PS:#nginx -V查看版本号及上一次编辑安装的参数


4、基本配置
http配置方式

server {
  server_name g.www.fity.cn; #<你的域名>
  listen 80;

  resolver 8.8.8.8;
  location / {
    google on;
  }
}


https配置方式

server {
  server_name g.www.fity.cn; #<你的域名>
  listen 443;

  ssl on;
  ssl_certificate <你的证书>;
  ssl_certificate_key <你的私钥>;

  resolver 8.8.8.8;
  location / {
    google on;
  }
}


5、补充信息:
 (1)给Nginx配置生成一个自签名的SSL证书

    $ wget https://raw.githubusercontent.com/michaelliao/itranswarp.js/master/conf/ssl/gencert.sh
    $ chmod +x gencert.sh
    $ ./gencert.sh
    Enter your domain [www.example.com]: www.test.com          
    Create server key...
    Generating RSA private key, 1024 bit long modulus
    .................++++++
    .....++++++
    e is 65537 (0x10001)
    Enter pass phrase for www.test.com.key:输入口令
    Verifying - Enter pass phrase for www.test.com.key:输入口令
    Create server certificate signing request...
    Enter pass phrase for www.test.com.key:输入口令
    Remove password...
    Enter pass phrase for www.test.com.origin.key:输入口令
    writing RSA key
    Sign SSL certificate...
    Signature ok
    subject=/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=www.test.com
    Getting Private key
    TODO:
    Copy www.test.com.crt to /etc/nginx/ssl/www.test.com.crt
    Copy www.test.com.key to /etc/nginx/ssl/www.test.com.key
    Add configuration in nginx:
    server {
        ...
        ssl on;
        ssl_certificate     /etc/nginx/ssl/www.test.com.crt;
        ssl_certificate_key /etc/nginx/ssl/www.test.com.key;
    }


 (2)进阶配置、更多请参考
  Project/guide:https://github.com/cuber/ngx_http_google_filter_module

 (3)常见问题
  不能正确地重定向(此网页包含重定向循环ERR_TOO_MANY_REDIRECTS),请重新更新扩展并重新编译您的nginx:

# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.5 (Debian 4.4.5-8)
built with OpenSSL 0.9.8o 01 Jun 2010
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/root/ngx_http_google_filter_module --add-module=/root/ngx_http_substitutions_filter_module

#cd lnmp1.2-full/src;
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

#cd nginx*
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/root/google/ngx_http_google_filter_module --add-module=/root/google/ngx_http_substitutions_filter_module

#make && make install

cp -rf objs/nginx /usr/local/nginx/sbin/nginx


 (4)本文基于LNMP环境 Nginx1.8.0编写

 本文作者最后更新于2016-4-11 23:30

本文最后更新于 2015-11-12 21:34:48 并被添加「nginx google nginx反向代理」标签,已有 8076 位童鞋阅读过。
本文作者:未来往事
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处

相关文章

已有 2 条评论
  1. cary

    http 配置这一步要在哪边配置啊新手请多指教

    cary error: 121
    1. Rinald

      @cary

      nginx配置文件

      Rinald error: 121

此处评论已关闭