【发布时间】:2014-01-25 14:10:27
【问题描述】:
我在 Amazon 中有一个 ELB 设置,它指向两个运行 Nginx 的服务器。然后 Nginx 将本地请求转发到运行我们的 Node JS 应用程序的不同端口。
当我测试冗余时,如果我停止运行 Node JS 应用程序,Nginx 将返回一个 502 Bad Gateway,这是我完全预料到的。我遇到的问题是如何让 ELB 确定这是一个错误页面并且它应该停止向有问题的服务器发送请求? ELB 似乎将 Nginx 502 错误视为有效的 HTTP 请求,因此不会将其删除。
ELB 监视器也不显示任何 500 错误
编辑:
Nginx config:
server {
listen 80;
server_name *.domain.com XX.XX.XX.XX;
access_log off;
client_max_body_size 2048M;
rewrite ^(.*) https://$host$1 permanent;
add_header X-Whom USE1A-01;
}
server {
listen 443;
ssl on;
ssl_certificate /ssl.crt;
ssl_certificate_key /ssl.key;
server_name *.domain.com XX.XX.XX.XX;
access_log off;
client_max_body_size 2048M;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_pass https://127.0.0.1:XXXX;
}
}
当应用未运行时,我的 nginx 访问日志显示的运行状况检查内容:
10.50.101.244 - - [07/Jan/2014:21:31:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:31:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:31:54 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:32:04 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:32:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:32:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:32:54 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:33:04 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:33:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:33:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0
【问题讨论】:
-
您的健康检查是如何配置的?您的健康检查是否会执行一个请求,该请求会一直传递到您的 node.js 应用程序?
-
是的,我有一个特定的页面 /healthCheck 将对数据库进行简单检查。如果我停止应用程序,Nginx 会显示 502 bad gateway。问题是,它不会进入 nginx 错误日志 - 它显示在 nginx 访问日志中。我相信 ELB 不会将此视为错误,并且我不确定如何配置 Nginx 以向 ELB 进行识别。我在帖子中添加了一些信息
-
ELB 收到 200 代码响应。这就是为什么它没有失败。运行状况检查是通过 http 还是 https?
-
HTTP。既然我将所有请求都重定向到 HTTPS,那这就是我需要做的吗?
-
好的,在 ELB 上将其切换为 HTTPS。谢谢!
标签: node.js amazon-web-services nginx amazon-elb