amazon web services - non www to www using AWS Elastic Load balancer and Nginx -


i have app running on example.com , wanna redirect traffic www.example.com since collaborating akamai's cdn website. domain parked in route53, added cname of elastic load balancer's cname pointing *.example.com , running nginx web server following configuration. if use configuration elb throwing instance out, domain.com works fine , www.domain.com fine, redirecting not happening.

server {         listen 80;         server_name example.com; #       rewrite ^    http://www.example.com$request_uri? permanent;         root /home/ubuntu/apps/st/public;         passenger_enabled on; } 

but not able achieve redirect.

also tried add ptr value cname of load balancer.

tried change nginx configuration, can see

rewrite ^ http://www.example.com$request_uri? permanent;

even not working.

as add above line, app instance goes , elb throws out of stack.

what solution, have been trying achieve since 3-4 days, become night mare now, kindly me up. have put posts , threads in aws forums, nothing helping such.

i had same issue redirect (using same nginx conf code shown here).

then, put redirect configs last server{} block (at end of domain.com config file), , elb able find instances again.

i have not looked more it, seems vhost processing done in order, when elb hits ip address of servers, lands on first defined server{} block, in case redirect. nginx throws 301 return code, , elb freaks out since not 200.

just guess though.

so, config (real vhost on top, redirect last):

less /etc/nginx/sites-enabled/domain.com

server {     listen 80;     server_name domain.com;     ..... }  server {     listen       80;     server_name  www.domain.com;     return       301 http://domain.com$request_uri; } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -