Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jelastic Nginx http to https redirect

I have an account in Jelastic and I want to force my site to work only over https. I've created environment nginx + php with nginx balancer and enabled Jelastic SSL (as it described here).

Whenever I tried to setup 301 redirect from http to https with no luck. Using mod_rewrite didn't work for me, the only thing I've got is a loop redirect. Google didn't help.

I really need advise. Any additional info will be provided.

Thanks in advance.

like image 715
JDF Avatar asked Dec 14 '22 06:12

JDF


1 Answers

The accepted solution did not work for my setup. I had to change the if statement to the following:

if ($http_x_forwarded_proto != "https") {
  return 301 https://$host$request_uri;
}

As described in the official nginx documentation https://www.nginx.com/blog/creating-nginx-rewrite-rules#https you should use:

return 301 https://$host$request_uri;

which works as well.

like image 184
Thomas Rawyler Avatar answered Jan 05 '23 04:01

Thomas Rawyler