Steven SullivanSteven Sullivan - 14th March 2017

Very simple trick here, but has a few people at a road block. If you’re running NGINX on VestaCP then the following will redirect all HTTP traffic to HTTPS traffic. Just make sure you’ve got a SSL certificate set-up and working.

Redirect HTTP to HTTPS

Create a new file (if you already have it, place the next bit of code inside it) at /home/USER/conf/web/nginx.vestacp.com.conf (replace USER with your VestaCP Username) and add the following code:

if ($scheme = http) { return 301 https://vestacp.com$request_uri; }

Replace https://vestacp.com with your own domain name.

 

Redirect HTTPS to HTTP

Similarly if you want to redirect all secure traffic to non secure then use this code instead:

if ($scheme = https) { return 301 http://vestacp.com$request_uri; }

Replace http://vestacp.com with your own domain name.

4 thoughts...

    1. SSULLIVAN88 says:

      If it was bad they would have removed it 😉

      1. JꙨ dцӍoηҬ says:

        if 🙂 I understood properly

        at this level in the nginx config the if is evil because it will be evaluate at every queries

        https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#server-name-if

        1. Thanks for sharing! Really appreciate it. 😀

          I imagine then that for very high traffic websites (we’re talking hundreds of millions of hits) it’s not ideal however, it’s just like .htaccess. The .htaccess file is evaluated at every query too and Apache and .htaccess are still a dominant, even if used as a proxy.

Leave a Reply

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