I want to redirect all the HTTP request to https request on ELB. I have two EC2 instances. I am using nginx for the server. I have tried a rewriting the nginx conf files without any success. I would love some advice on it.
相关问题
- Stop .htaccess redirect with query string
- JQ: Select when attribute value exists in a bash a
- Can ServiceStack JsonServiceClient send a get requ
- UrlEncodeUnicode and browser navigation errors
- How can I prevent my Shiny App from disconnecting
I had strange problem with nginx and ELB configuration. My setup included 3 different services inside one nginx behind ELB. And I had mixed content issue: when your request to ELB is https, but inside ELB http only, and server create relative path to static using http, so browser fails with 'mixed content' issue. And I must create solution for both http/https work without any redirects.
Here is config located in
nginx/conf.d/
folder:This means that we will have knowledge what real client protocol is. As you can see, we will have it in
$switch
var. And at this moment you use this in all location where you need it:With HTTPS setting php application will automatically detect right protocol and carefully build relative path for preventing mixed content issue.
Best regards.
AWS Application Load Balancers now support native HTTP to HTTPS redirect.
To enable this in the console, do the the following:
The same can be achieved by using the CLI as described here.
It is also possible to do this in Cloudformation, where you need to set up a Listener object like this:
If you still use Classic Load Balancers, go with one of the NGINX configs described by the others.
Create a file
.ebextensions/00_forward_http_to_https.config
with the following content:Make sure to set the APP_URL environment variable from the AWS management console beforehand.