Correct Rewrite?

We currently use the following method to perform an http to https

rewrite ^ https://$server_name$request_uri permanent;

I am planning to change it to the preferred method of:

return 301 https://$server_name$request_uri;

However, we’d like to also make sure any requests for are
sent to, whether someone tries to access via http or

How would I write the redirect statement to rewrite http:// to https://
also rewrite to

Posted at Nginx Forum:

The way I do this is to use multiple server {} blocks, and put all the
non-canonical hostnames / port 80 requests in a server block with a
301 to the canonical (and HTTPS) host which only listens on 443 and the
canonical hostname.

On Fri, Mar 11, 2016 at 9:12 PM, mevans336 [email protected]

That seems like a very elegant way to handle the problem. I’ll give it a
shot. Thanks!

Posted at Nginx Forum: