Icharle | Don't forget your first thoughts - https
https://icharle.com/tag/https
-
Nginx强制http重定向到https
https://icharle.com/https.html
2017-02-03T04:36:00+08:00
前言
利用上一篇文章申请免费SSL申请的SSL证书
原理
将80端口(HTTP)全部301重定向到HTTPS
Nginx强制https规则
配置Nginx一般是打开nginx.conf文件或者是域名.conf文件
添加如下代码
if ($server_port = 80) {
return 301 https://$server_name$request_uri;
}
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
error_page 497 https://$server_name$request_uri;
最后保存,重启nginx。