• 欢迎访问爱玩吧
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏爱玩吧

[教程]Nginx环境强制http 301跳转https的方法

实用教程 aiwanyule 3年前 (2021-05-12) 已收录
文章目录[隐藏]

说明:现在越来越多的人开始为网站启用ssl证书了,安装了ssl后我们都需要让http强制跳转https,并确定网站唯一性,这里介绍了几种方法。

方法

提示:以军哥的lnmp一键安装包为例,Nginx配置文件修改地址为/usr/local/nginx/conf/vhost/xx.com.conf
[教程]Nginx环境强制http 301跳转https的方法
方法一:

if ($scheme = http ) {
return 301 https://$host$request_uri;
}

方法二:

server_name moerats.com ;
rewrite ^(.*) https://moerats.com$1 permanent;

方法三:

if ($server_port = 80 ) {
return 301 https://$host$request_uri;
}

方法四:

server_name moerats.com ;
return 301 https://$server_name$request_uri;

最后输入/etc/init.d/nginx restart重启Nginx即可


爱玩吧 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:[教程]Nginx环境强制http 301跳转https的方法
喜欢 (0)