欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

Nginx实现http自动跳转到https

时间:2025-12-13 18:30:04|栏目:其它服务器|点击:

https是更安全的http,通过http自动跳转https,可以更便于用户使用web。

有几下几个方法可以完成跳转:

1.打开http和https的server,让http跳转到https

server {
    listen 80;
    listen [::]:80;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    ssl_certificate         certificate_file_path;
    ssl_certificate_key  certificate_key_file_path;

    ...

}

2.不打开http的server,直接在https的server里完成跳转,以下三种方式都可以

server {

    if ($server_port = 80 )   

    #if ($scheme = http )

    #if ($ssl_protocol = "")

    {
        return 301 https://$host$request_uri;
    }

    
    listen 443 ssl;
    listen [::]:443 ssl;

    ssl_certificate         certificate_file_path;
    ssl_certificate_key  certificate_key_file_path;

    ...

}

上一篇:Windows server 2019 如何安装IIS并勾选正确参数

栏    目:其它服务器

下一篇:Nginx IP封禁及自动封禁IP的实现

本文标题:Nginx实现http自动跳转到https

本文地址:https://zz.feitang.co/server/30616.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号