大网数据广告活动
服务器运维问答

Nginx : AWS Route 53 : ELB : naked redirect

· 52CE 我爱测

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…

问题原文

原帖链接 · 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;
 }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-01-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。