安裝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/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