これは、HTTPとHTTPSの両方を処理するNginX VirtualHostsで、要求されたHTTP URLをHTTPSにリダイレクトする実用的な方法です。
たとえば、単一のvhostでHTTPとHTTPSの両方をサポートするには、通常、次のディレクティブがあります。
# Support for HTTP and HTTPS
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/www.myserver.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.myserver.com/privkey.pem;
次に、無限ループを作成せずにこの仮想ホスト内のすべてのHTTPリクエストをHTTPSにリダイレクトするには、次のリダイレクトを追加します。
if ($scheme != "https") {rewrite ^ https://$host/$request_uri permanent;}
他の方法はここで見ることができます:
http://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while -maintaining-sub-dom