1

Setup
I have two rails app instances running in Opsworks Layer. I am using Route 53 and an ELB to route traffic to my Layer.

Objective
To redirect naked domain traffic to my www domain. chicken.com -> www.chicken.com

What I tried
I Alter my nginx conf (on one instance) to solve this problem. I added the following:

server {
 listen 80;
 server_name chicken.com;
 return 301 $scheme://www.chicken.com$request_uri;
}
... rest of config here

Result
Instance is no longer hittable by its IP.

ELB marked the instance I had altered as "Out of Service" since it could no longer be reached by IP (the health check fails).

Question
How can I route naked domains to www domains yet keep my ELB health checks happy?

1

You need to setup something that'll return 2xx on the health check, currently the 301 is making the ELB think it's out of service, you could put something like this

server {
 listen 80;
 server_name chicken.com;

 location ^~ /health {
   proxy_pass http://my_proxy;
 }

 location / {
   return 301 $scheme://www.chicken.com$request_uri;
 }

}

server {
 listen 80;
 server_name www.chicken.com;

 location / {
   proxy_pass http://my_proxy;
 }
}
  • could you explain my_proxy.. a bit more, I dont think I get it. – mconlin Jan 14 '15 at 2:01
  • I want /health to just be served, and everything else to return 301 to www.chicken.com. I am not sure how the proxy_pass to my_proxy does that.. is there an idea of http://<self>? in nginx? – mconlin Jan 14 '15 at 2:53
  • sorry, so many configurations use proxy_pass that I thought I could use it as the example... basically -- however you're serving your site, that is the "rest of config" bit you mention -- goes inside the locations bit instead of proxy_pass – c4urself Jan 14 '15 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.