将aws alb目标组的协议改为http2是否能提高速度?如何设置?

0

【以下的问题经过翻译处理】 我知道从http1到http2的转变可以提高速度。

所以我配置允许alb和cloudfront使用http2。在Chrome浏览器的开发者工具中,我确认了协议为h2并且应用了http2。

然而,在搜索的过程中,有人认为将aws elb目标组的协议改为http2可以提高速度。因此,我使用与http1相同的设置将协议改为http2,但是出现了502错误。,例如使用负载均衡器DNS地址连接到随机端口(例如:8080端口),在http1.1设置时没有错误。

问题是,如果在浏览器中检查协议时显示h2,那么它是否应用于http2,还是应该在目标组协议中内部设置为http2?如果需要设置它,该如何避免出现502错误?

profile picture
EXPERTE
gefragt vor 5 Monaten12 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 当您将ALB目标组协议启用为HTTP/2时,需要确保目标也支持协议版本HTTP/2。例如,如果您正在使用nginx,则可以将服务器部分更新为:

server {
        listen       80 http2 ;
        listen       [::]:80 ;

如果服务器未配置为支持HTTP/2协议版本,则目标服务器将向ALB发送 400 错误请求。我在我的环境中进行了测试,并且从目标捕获的数据包显示向ALB发送了以下400错误请求响应。

PRI * HTTP/2.0
HTTP/1.1 400 Bad Request
Server: nginx/1.20.0
Date: Thu, 23 Feb 2023 05:06:42 GMT
Content-Type: text/html
Content-Length: 157
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.20.0</center>
</body>
</html>

ALB向目标的请求数据包: Enter image description here

当ALB从目标获取此400 错误请求响应时,它可能向客户端生成502错误请求代码。

如果您已经为HTTP2配置了目标,则可以在此处检查其他可能的502原因 https://aws.amazon.com/premiumsupport/knowledge-center/elb-alb-troubleshoot-502-errors/。

就性能而言,当您拥有端到端的HTTP2时,压缩头可以节省一些数据传输成本。

profile picture
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen