Icharle | Don't forget your first thoughts - https https://icharle.com/tag/https zh-CN Fri, 03 Feb 2017 04:36:00 +0800 Fri, 03 Feb 2017 04:36:00 +0800 Nginx强制http重定向到https https://icharle.com/https.html https://icharle.com/https.html Fri, 03 Feb 2017 04:36:00 +0800 Icharle Nginx2-1

前言

利用上一篇文章申请免费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。

]]>
0 https://icharle.com/https.html#comments https://icharle.com/feed/https.html