CENTOS下安装LNMP后,默认是不带反向代理所需要的模块的,需要增加第三方模块,
根据https://github.com/cuber/ngx_http_google_filter_module/blob/master/README.zh-CN.md总结的方法如下:
cd /root/lnmp1.2-full/src #进入LNMP安装目录
git clone https://github.com/cuber/ngx_http_google_filter_module #下载模块
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module #下载模块
cd nginx-1.7.8 #进入NGINX目录
make clean #清除以前的配置
#编译配置
./configure \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_gzip_static_module \
--with-ipv6 \
--with-http_sub_module\
#以上为LNMP安装自带的模块,需要加入以下两行
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module
make && make install #即可安装完成.

最后新建一个虚拟主机配置文件,删除原来的内容,填入如下内容:

server {
listen 443 ssl;
server_name gg.zhtube.com;

ssl on;
ssl_certificate gg.zhtube.com.crt;
ssl_certificate_key gg.zhtube.com.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
keepalive_timeout 70;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

resolver 8.8.8.8;

location / {
google on;
}
}

证书可以自行添加,以后有时间写个获取证书的内容,最后效果如网站演示:

https://gg.zhtube.com/

也可以在浏览器中加入自定义搜索如下内容:

https://gg.zhtube.com/search?num=50&hl=zh-cn&newwindow=1&c2coff=1&safe=off&q=%s

1.将所有HTTP80访问跳转到HTTPS443访问,此方法所有访问此域名80端口的访问都将跳转到443

#301跳转 将80请求全部转发到https
server {
listen 80;
server_name zhtube.com www.zhtube.com;

location / {
rewrite (.*) https://www.zhtube.com$1 permanent;
}
}

server {
listen 443 ssl;
server_name zhtube.com www.zhtube.com;

root /home/vhost/www.zhtube.com;

ssl on;
#这是你的证书目录
ssl_certificate /usr/loacl/nginx/ssl-crt/zhtube.com.crt;
#这是你的证书key目录
ssl_certificate_key /usr/loacl/nginx/ssl-crt/zhtube.com.key;

location / {
index index.php;
}

}

2.HTTP80和HTTPS443同时访问

server {
listen 80;
listen 443 ssl;
server_name www.zhtube.com;

ssl_certificate /usr/loacl/nginx/ssl-crt/zhtube.com.crt;
ssl_certificate_key /usr/loacl/nginx/ssl-crt/zhtube.com.key;

root /home/vhost/www.zhtube.com;
}