Nginx 配置 HTTP 跳转 HTTPS

参考文献:Configuring HTTPS servers,还是官方 Document 比较靠谱。

server {
    listen              80;
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;
    ...
}

然后添加一个跳转判断即可:

    #rewrite to SSL
    if ($scheme = http) {
            return 301 https://$server_name$request_uri;
    }

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.