在CentOS下使用ngx_http_google_filter_module
安装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_modulemake
make && make installSSL证书
申请证书的网址:https://zerossl.com/free-ssl/#self
网站会提示下载两个文件,一个是crt.txt 文件,一个是key.txt文件,这两个就是证书和秘钥
当然你要使用的话需要修改一下域名,你还可以使用openssl命令或者使用Let’s Encrypt
随便你使用哪个都可以,个人喜欢使用这个网址简单几步操作就可以了
把证书上传到服务器上
Nginx设置
mkdir /usr/local/nginx-1.8.0/conf/vhost cd /usr/local/nginx-1.8.0/conf/ vi nginx.conf在底部加入:
include vhost/*.conf;然后保存并退出。
cd vhost vi 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
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。