在CentOS下使用ngx_http_google_filter_module

来源:互联网 发布:淘宝怎么取消延长收货 编辑:程序博客网 时间:2024/06/15 18:48

安装Git&GCC

yum -y update && yum -y groupinstall "Development Tools" && yum -y install git gcc make epel-release
下载组件

wget http://nginx.org/download/nginx-1.8.0.tar.gz && wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz" && wget "https://www.openssl.org/source/openssl-1.0.1j.tar.gz" && wget "http://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 xzvf nginx-1.8.0.tar.gz && tar xzvf pcre-8.38.tar.gz && tar xzvf openssl-1.0.1j.tar.gz && tar xzvf zlib-1.2.11.tar.gz
添加用户,可以在nginx.conf配置文件中修改

groupadd www && useradd -s /sbin/nologin -g www www
进入Nginx目录,编译

cd nginx-1.8.0
./configure \ --prefix=/usr/local/nginx-1.8.0 \ --with-pcre=../pcre-8.38 \ --with-openssl=../openssl-1.0.1j \ --with-zlib=../zlib-1.2.11 \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_spdy_module \ --with-http_gzip_static_module \ --with-ipv6 \ --with-http_sub_module \ --add-module=../ngx_http_google_filter_module \ --add-module=../ngx_http_substitutions_filter_module
make

make && make install
SSL证书

申请证书的网址:https://zerossl.com/free-ssl/#self

网站会提示下载两个文件,一个是crt.txt 文件,一个是key.txt文件,这两个就是证书和秘钥

当然你要使用的话需要修改一下域名,你还可以使用openssl命令或者使用Let’s Encrypt

随便你使用哪个都可以,个人喜欢使用这个网址简单几步操作就可以了

把证书上传到服务器上

Nginx设置

mkdir /usr/local/nginx-1.8.0/conf/vhostcd /usr/local/nginx-1.8.0/conf/vi nginx.conf
在底部加入:

include vhost/*.conf;
然后保存并退出。

cd vhostvi gotogoogle.conf
加入以下内容,根据自己实际需要修改:

server { server_name <你的域名>; listen 443; ssl on; ssl_certificate <你的证书>; ssl_certificate_key <你的私钥>; resolver 8.8.8.8; location / { google on; google_scholar on; }}upstream www.google.com { server 216.58.216.196:443; server 216.58.216.195:443; server 216.58.216.194:443; server 216.58.216.193:443; server 216.58.216.192:443;}
Start Nginx

/usr/local/nginx-1.8.0/sbin/nginx -c /usr/local/nginx-1.8.0/conf/nginx.conf
如果修改了配置文件:

/usr/local/nginx-1.8.0/sbin/nginx -s reload
访问:https://你的域名


最后,注明,一切步骤操作完成之后,记住需要关闭vps的防火墙,或者是增加端口,我就是忘记了防火墙的原因,在这卡了好久;如果不知道如何申请域名,请看我另一份博客申请免费域名

推荐使用命令:

sudo firewall-cmd --permanent --add-port=443/tcp

sudo  firewall-cmd --reload













原创粉丝点击