电商安全 mall-https

您现在所在的位置 首页 > 电商安全 > Nginx以及单页面http自动跳转https方法

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

受互联网严峻的安全形势以及搜索巨头优先收录https网站的影响,https站点开始大行其道,越来越多的http站点开始向https站点过度,本文介绍nginx中以及单页面中如何实现http自动跳转到https。

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>

apache如何设置http自动跳转到https

iis中http自动跳转https方法

apache中http强制跳转https方法

nginx https配置方法:http和https共存