linux - nginx http to https redirection issue -


i trying redirect http://example.com , https://example.com , http://www.example.com https://www.example.com . servers listening both http , https requests via 443 port through elb.

nginx config :

server {       listen 443;       server_name example.com;       return 301 $scheme://www.example.com$request_uri;     }      server {             listen       443 default;             server_name  www.example.com;             //ssl stuffs             }   

only http://example.com , https://www.example.com working expected.but http://www.example.com going infinite redirection loop.

what might wrong config file. appreciated.

create server blocks handle redirection.

server {     listen 80;     server_name www.example.com example.com;     return 301 https://www.example.com$request_uri; } server {     listen 443;     server_name example.com;     return 301 https://www.example.com$request_uri; } server {     listen 443;     server_name www.example.com;     // ... } 

update 1:

use x-forwarded-proto request header identify protocol (http or https) client used connect server.

server {     listen 443;     server_name example.com;     return 301 https://www.example.com$request_uri; } server {     listen 443;     server_name www.example.com;     if ($http_x_forwarded_proto = 'http') {         return 301 https://www.example.com$request_uri;     }     // ... } 

source: http://docs.aws.amazon.com/elasticloadbalancing/latest/developerguide/x-forwarded-headers.html


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -