Rewrite HTTP requests to HTTPS using Nginx

A common task is to rewrite HTTP requests to HTTPS to secure communication. Using nginx, this is easily done with:

        # use only https
        if ($scheme = http) {
                rewrite ^ https://$host$uri permanent;
        }

This should be placed in a server block.

Leave a Reply

Your email address will not be published. Required fields are marked *