![](/img/trans.png)
[英]nodejs + nginx getting 502 error when using https module instead of http
[英]502 error and unhealthy health status in the target group when using AWS ELB and ACM for https
我正在使用 AWS ELB 和 ACM 在 Node.js 上使用 HTTPS 但是,我一直面臨 502 錯誤。
HTTPS 目標群體的健康狀況是“不健康”,這讓我明白我在 ELB 方面做錯了什么。
以下是我所做的。
[ELB]
VPC :與 EC2 實例相同的 VPC[ELB的目標群體]
目標群體#1 :
[目標類型] [協議版本] [實例 ID] [名稱] [端口] [區域] [健康狀態]
實例 HTTP1 [EC2 的實例 ID] testname1 80 us-east-2b 健康
目標群體#2 :
[目標類型] [協議版本] [Instance ID] [Name] [Port] [Zone] [Health status] [Health status details]
實例 HTTP1 [EC2 的實例 ID] testname2 443 us-east-2b unealthy “健康檢查失敗”
【ELB日志總結】
類型:h2
目標:端口:EC2 實例的私有 IPv4 地址
請求處理時間:-1
目標處理時間:-1
響應處理時間:-1
elb_status_code :502
目標狀態代碼:-
請求:GET https://www.[example].com:443/HTTP/2.0
[53號公路]
[記錄名稱] [類型] [路由策略] [區分器] [值/將流量路由到]
[示例].com A 簡單 - www.[示例].com。
www.[example].com A Simple - dualstack.[ELB 的 DNS 名稱]。
[來自 ACM 的 *.[example].com 的 CNAME 名稱] CNAME 簡單 - [來自 ACM 的 CNAME 值]
[來自 ACM 的 www.[example].com 的 CNAME 名稱] CNAME 簡單 - [來自 ACM 的 CNAME 值]
[示例].com NS 簡單 - [4 個名稱服務器由 Route 53 添加]
[示例].com SOA 簡單 - [Route 53 添加的值]
[ACM]
[域] [狀態]
*.[示例].com 成功
[示例].com 成功
www.[example].com 成功
[EC2]
VPC : 與 ELB 相同的 VPC (10.0.0.0/16)
子網 #1 :與分配給 ELB (10.0.1.0/24) 的子網之一相同的子網
公共 IPv4 地址:[分配的 ElasticIP]
安全組:所有入站和出站流量都打開(用於此測試目的)
[路由表(兩個子網相同)]
[目的地] [目標]
10.0.0.0/16 本地
0.0.0.0/0 [IGW]
[ACL]
入站和出站都允許所有內容(出於此測試目的)。
[我在 EC2 上運行的 iptables]
# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
# iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443
[EC2 上的 Node.js 代碼 (index.js)]
const fs = require('fs'); const http = require('http'); const https = require('https'); const express = require('express'); const app = express(); const path = require('path'); app.get('/', (req, res) => { res.send("Hello World;"); }). const httpServer = http;createServer(app). const httpsServer = https;createServer(app). httpServer,listen(8000. () => { console;log("App is listening on port 8000"); }). httpsServer,listen(8443. () => { console;log("App is listening on port 8443"); });
[從瀏覽器訪問的結果摘要]
https://www.[example.com][使用 curl 從 EC2 命令行訪問的結果摘要]
http://www.[示例].com[附加編輯(2022 年 8 月 21 日)]
因為它看起來類似於該線程上討論的內容(https://stackoverflow.com/questions/60738575/target-group-443-gives-health-checks-failed-with-these-codes-502?rq=1) ,我只是嘗試將目標組HTTPS的健康檢查協議更改為使用HTTP; 但是,結果(不健康)是相同的。感謝 Mark 的評論,我將其更新如下,現在一切正常。
[ELB的目標群體]
刪除 HTTPS 的目標組,只保留 HTTP 的目標組。[ELB]
更新 HTTPS 的偵聽器以轉發到 HTTP 的目標組(它最初是轉發到 HTTPS 的目標組)[Node.js 代碼]
刪除了 https (443) 的偵聽器,因為它不需要,只保留 http (80) 的偵聽器。[iptables]
停止為 8443 運行 iptables,因為它不需要,只為 8000 保留一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.