探索,發現,愛好、學習,記錄,分享。
學海無涯,天涯若比鄰,三人行,必有我師。

Nginx以及单页面http自动跳转https方法

在配置80端口的文件里面,写入以下内容即可。

server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;

location / {
root html;
index index.html index.htm;
}

单页面中配置http自动跳转https方法
在需要强制为https的页面上加入该代码进行处理
<script type=”text/javascript”>
var url = window.location.href;
if (url.indexOf(“https”) < 0) {
url = url.replace(“http:”, “https:”);
window.location.replace(url);
}
</script>

版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權
轉載事宜:如需轉載需徵得應允,轉載必須注明來源於本站的信息。
文章名称:《Nginx以及单页面http自动跳转https方法》
文章链接:https://www.thefreesky.com/blog/23464.html
本站資源僅供個人學習交流,請於下載後24小時內刪除,不允許用於商業用途,否則法律問題自行承擔。

評論 抢沙发