Nginx环境强制http 301跳转https的方法

admin 2022年5月16日21:11:30系统文档评论1,715 次浏览阅读模式

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

方法

提示:以军哥的lnmp一键安装包为例,Nginx配置文件修改地址为/usr/local/nginx/conf/vhost/xx.com.conf。

方法一:

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即可


相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2022年5月16日21:11:30
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/xitongwendang/2022/0516/10900.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: