在 nginx 中將 http 重新導向到 https

如何在 nginx 設定中將 http 流量重新導向至 https。

server {
    listen  80;
    server_name domain.name;
    return 301 https://$server_name$request_uri;
}

server {
    listen   443 ssl;
    ssl_certificate  domain.name.crt;
    ssl_certificate_key  domain.name.key;
    server_name  domain.name;
    location / {
        ...
    }
}

參考文獻

nginx