Reputation: 8733
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?
Upvotes: 0
Views: 1293
Reputation: 10859
The ELB health check expects a 200 response. Are you checking against chicken.com instead of www.chicken.com? A redirect page is not sufficient for the health check.
To have both the redirect and provide a 200 response for the ELB check (coming from an internal IP), use the following config:
server {
listen 80;
server_name chicken.com;
return 301 $scheme://www.chicken.com$request_uri;
}
server {
listen 80 default_server;
server_name www.chicken.com;
...
Note the default_server
option. If not set, the first server
defined is the default one. See the nginx docs for details.
Upvotes: 1