server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 307 https://$host$request_uri;
}
A 301 redirect is also an alternative but if a POST is made to a 301, then many clients will resubmit the request as a GET - whic...