I have a spring boot application (1.5.3) which is running on a Tomcat container with Nginx as the load balancer. I have created below file:
.ebextentions/nginx/conf.d/myapp.conf
And I added the below content based on this article:
server {
if ($http_x_forwarded_proto != 'https') {
rewrite ^(.*) https://$host$1 redirect;
}
}
I have installed SSL certificate in certificate manager and set it in my environment. Now the application serves both HTTP and https request. I want to redirect all HTTP requests to https without falling into a redirect loop. but doesn't work.
I don't think you should add the server part to the .conf file. The entire .conf file should be something like this:
if ($http_x_forwarded_proto = 'http') {
return 301 https://www.example.com$request_uri;
}
See this answer on Server Fault.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With