美文网首页
Nginx开启HTTPS,HTTP自动重定向至HTTPS

Nginx开启HTTPS,HTTP自动重定向至HTTPS

作者: 水明 | 来源:发表于2020-02-06 01:16 被阅读0次

    首先申请一份SSL证书,获得证书文件.crt,证书key文件.key
    Nginx配置如下

    server {
      listen 80;
      server_name website.com;
    
      # 重定向至https
      rewrite ^(.*)$ https://$host$1 permanent;
    }
    
    server{
      listen 443 ssl;
      server_name walterbright.cc;
    
      # ssl 证书路径
      ssl_certificate       path/cert.crt;
    
      # ssl key 路径
      ssl_certificate_key   path/cert.key;
    
      location / {
        root /site/;
      }
    }
    

    相关文章

      网友评论

          本文标题:Nginx开启HTTPS,HTTP自动重定向至HTTPS

          本文链接:https://www.haomeiwen.com/subject/xlfyxhtx.html