Amazon-Web-Services

AWS Elastic Load Balancer HTTP 執行狀況檢查 ping 未到達 Rails 應用程序伺服器

  • August 26, 2015

我剛剛繼承了一個在 AWS Elastic Beanstalk 上執行的 Ruby + Rails 應用程序,它目前正在使用 TCP 進行 Elastic Load Balancer 執行狀況檢查。我希望切換到 HTTP,並實際點擊我的應用程序。

為此,我在始終返回狀態 200 的應用程序上創建了一個端點。我部署它,並使用 curl 對其進行測試。

louis $ curl -I https://my.domain.goes.here/__status__
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Date: Tue, 25 Aug 2015 16:09:29 GMT
ETag: W/"028714d01e3aa7ed0ffa7a023f82ca94"
Server: nginx/1.6.2
Strict-Transport-Security: max-age=31536000
X-Request-Id: 1ce6b907-779a-45d2-b9f9-d19a74ef8abd
X-Runtime: 0.002703
Connection: keep-alive

這是我預期的結果。

我使用 AWS 控制台通過以下配置設置執行狀況檢查:

Ping Target          HTTP:80/__status__
Timeout              5 seconds
Interval             30 seconds
Unhealthy Threshold  5
Healthy Threshold    3

但是現在健康檢查一直失敗。埠 443 上的 HTTPS 相同

我 ssh 進入實例並從那裡捲曲。

# With the "Private IP"
[ec2-user@ip-$PRIVATE_IP_ADDRESS ~]$ curl -I $PRIVATE_IP_ADDRESS/__status__
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 26 Aug 2015 08:14:21 GMT
Content-Type: text/html
Connection: keep-alive
Location: https://$PRIVATE_IP_ADDRESS/__status__

# With the "Private DNS"
[ec2-user@ip-$PRIVATE_IP_ADDRESS ~]$ curl -I $PRIVATE_DNS_ADDRESS/__status__
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 26 Aug 2015 08:17:20 GMT
Content-Type: text/html
Connection: keep-alive
Location: https://$PRIVATE_DNS_ADDRESS/__status__

# With the "Public IP"
[ec2-user@ip-$PRIVATE_IP_ADDRESS ~]$ curl -I $PUBLIC_IP_ADDRESS/__status__
curl: (7) Failed to connect to $PUBLIC_IP_ADDRESS port 80: Connection timed out

# With the "Public DNS"
[ec2-user@ip-$PRIVATE_IP_ADDRESS ~]$ curl -I $PUBLIC_DNS_ADDRESS/__status__
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 26 Aug 2015 07:24:37 GMT
Content-Type: text/html
Connection: keep-alive
Location: https://$PUBLIC_DNS_ADDRESS/__status__

# With the "Public DNS" over HTTPS
[ec2-user@ip-$PRIVATE_IP_ADDRESS ~]$ curl -I https://$PUBLIC_DNS_ADDRESS/__status__
curl: (7) Failed to connect to $PUBLIC_DNS_ADDRESS port 443: Connection refused

這裡可能有什麼問題?

ELB 不會命中你的域名,它會命中你的 IP 地址。測試curl -I https://my.**IP**.goes.here/__status__以驗證您的狀態檢查是否正常工作 - 它會命中預設虛擬主機。

**編輯:**根據您更新的結果,您的伺服器正在將您的 HTTP 訪問重定向到 HTTPS。ELB 不認為 301 是成功的,因此它會將其視為失敗。從 HTTP → HTTPS 重定向中免除您的狀態頁面。

引用自:https://serverfault.com/questions/716691