一、如何将http升级到https
需要满足下面三个:
1.域名
2.nginx
3.SSL证书
一般第三方证书颁发机构下发的证书是收费的,一年好几千。
1) 从腾讯云申请免费的SSL证书,有效期一年,可申请多个
SSL 证书申请地址在这里: https://console.qcloud.com/ssl
申请过程几分钟就可以搞定,主要分两步
1.申请免费的证书,设置手动DNS验证
2.到域名对应的域名解析商处添加解析记录
下载申请好的域名,上传到服务器指定位置
2) nginx配置
2.1.使Nginx 支持 SSL
1)检查 Nginx 是否支持 SSL
/usr/local/nginx/sbin/nginx -V
configure arguments中是否有--with-http_ssl_module
如:
nginx version: nginx/1.13.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_ssl_module
2) 若不支持,为nginx添加SSL 模块
进入nginx安装目录执行:
./configure --with-http_ssl_module
然后,注意不要make install
make
3)备份原 Nginx 执行脚本
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
4)将新版本 Nginx 编译脚本放到可执行文件目录下
cd objs/ cp nginx /usr/local/nginx/sbin/
5)进行平滑升级
make upgrade
再次检查是否安装成功:
/usr/local/nginx/sbin/nginx -V
2.2.编辑Nginx配置文件
cd /usr/local/nginx/conf
vim nginx.conf
server {
listen 443 ssl;
server_name 你的域名;
ssl_certificate 你的证书.crt;
ssl_certificate_key 你的证书.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
二、同时支持http和https两种请求
nginx配置新增server的配置
# http -> https
server {
listen 80;
server_name 你的域名;
rewrite ^(.*)$ https://$host$1 permanent;
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容