Redirect HTTP to HTTPS in VestaCP with NGINX

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 and add the following code:

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

Where USER and vestacp.com are – replace with the username and 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; }

Where USER and vestacp.com are – replace with the username and domain name.