+9

Ajenti-V http to https redirection

alex3138 5 years ago • updated by Costas Pap 1 year ago 6
Hello.

I access most of my websites using https but I always setup a redirection from http to https to avoid connection failing if I enter http://mywebsite.com.

So far, the only way I found to do it is to add a top-level custom configuration with the following code:

server {
listen 0.0.0.0:80;
server_name mywebsite.com;
return 301 https://$server_name$request_uri;
}

Is there a way of doing it from Ajenti-V UI ?
+3
The same problem.
I have site http://playdirect.me/ and https://playdirect.me/
http version should redirect to https.

the way mentioned above is ok, but server directive not allowed in ajenti Advanced tab :(
Any ideas?
It should be simple...
I would like to know if this is possible as well.

Used the example above of (see below) for the time being but something in the UI would be nicer.

server {
listen 0.0.0.0:80;
server_name mywebsite.com;
return 301 https://$server_name$request_uri;
}
+3

I'm using Cloudflare Universal SSL but this should work fine for a local cert as well. In the AjentiV dashboard, go to Websites -> yourwebsite.com -> Advanced and enter the following directive in the Custom Configuration text box:


if ($http_cf_visitor ~ '{"scheme":"http"}') {
return 301 https://$server_name$request_uri;
}


This is the only way I've found to avoid redirect loops while still working solely in the AjentiV UI. Hope it helps!

+5

$http_cf_visitor is registered only on Coudflare. On any common nginx you can do like this:


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

Works for me like a charm.

I have a fully functional setup but when I add the code Maxim Lanin suggests the redirection is activated however the site stops working. Should I configure nginx conf or any other file prior to adding this code? A full guide of configuring redirections on nginx including http to https, non-www to www, and SSL installation would really help. Thanks