问题原文
原帖链接 · mconlin · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · c4urself · CC BY-SA 3.0
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;
}
}
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
