Amazon ELB和Nginx服务器上的多域

我有一个EC2实例运行Nginx的几个域。 我的configuration是这样开始的:

server { listen 80; #disable_symlinks off; server_name _; #allow few domains #Adding 'www.' to url in case it doesen't if ($host !~* ^www\.) { rewrite ^(.*)$ http://www.$host$1 permanent; } location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php; } index index.html index.php; } 

我不知道在ELB(亚马逊)上使用哪个pingpath,因为如果我尝试HTTP,实例总是失败。 如果我尝试TCP(端口80)ping成功。 我必须使用HTTP,因为我想使用粘性。

有什么build议? 谢谢,丹尼

Serverfault上的另一个答案告诉我们,ELB除了200 OK状态代码之外什么都没有。
这对您的设置是一个问题,因为rewrite将导致3**状态代码。

为这个pingpath创build一个新的位置,如下所示:

 location = /elb-ping { return 200; } 

然后确保使用www。 为了避免redirect的ping

如果您不能将ping域更改为www。
您将不得不将redirect移动到www。 到一个server块。
或者你在你的configuration中定义一个静态的ping目标。

简单的方法

 server { listen 81; # What about using a different port for ELB ping? server_name _; # Match all if the listen port is unique, #server_name elb-instance-name; # Or match a specific name. return 200; # Not much magic. } server { listen 80; #disable_symlinks off; server_name _; #allow few domains #Adding 'www.' to url in case it doesen't if ($host !~* ^www\.) { rewrite ^(.*)$ http://www.$host$1 permanent; } location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php; } index index.html index.php; } 

方式太复杂了

 server { listen 80; # match hostnames NOT being www.* # Unfortunately matches only names with length >= 4 server_name ~^(?P<domain>[^w]{3}[^\.].*)$; location / { rewrite ^(.*)$ $scheme://www.$domain$1; # rewrite to www.* } location = /elb-ping { return 200; } } server { listen 80; server_name www.*; # match hostnames starting with www.* ## YOUR EXISTING CONFIG HERE (without the if block and elb-ping location) }