gpt4 book ai didi

node.js - Elastic Beanstalk 在配置菜单中没有负载均衡器设置

转载 作者:太空宇宙 更新时间:2023-11-03 22:09:19 25 4
gpt4 key购买 nike

enter image description here

我尝试在我的 Elastic Beanstalk 应用程序上启用 websocket,但在按照此处的说明 ( https://mitchellsimoens.com/websockets-behind-elastic-beanstalk/ ) 操作后,我发现应用程序的运行状况下降了。这可能是因为我未能在本说明中提到的配置菜单中找到负载均衡器设置。

这是我的配置菜单的屏幕截图:

enter image description here

显然,websocket 不适用于我的应用程序。事实上,在我将 .ebextensions/files.config 添加到我的项目后,整个应用程序都关闭了。当然,我的 process.env.PORT 是 80 而不是 3000(我想,不知道在哪里看)。

我尝试过这两种设置:

files:
"/etc/nginx/conf.d/01_websockets.conf" :
mode: "000644"
owner: root
group: root
content : |
upstream nodejs {
server 127.0.0.1:process.env.PORT;
keepalive 256;
}
server {
listen process.env.PORT;
large_client_header_buffers 8 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;

proxy_pass http://nodejs;
proxy_redirect off;

# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

files:
"/etc/nginx/conf.d/01_websockets.conf" :
mode: "000644"
owner: root
group: root
content : |
upstream nodejs {
server 127.0.0.1:80;
keepalive 256;
}
server {
listen 80;
large_client_header_buffers 8 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;

proxy_pass http://nodejs;
proxy_redirect off;

# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

最佳答案

扩展>单实例类型 EB 没有负载平衡设置,但是您所做的非常正确:

默认情况下,您需要监听 8080 而不是 80(AWS 很困惑),并且需要将流量发送到您正在使用的任何端口,在本例中为 80,所以...

您还需要删除旧的 nginx_confg 并重新启动实例/服务器。

files:
"/etc/nginx/conf.d/01_websockets.conf":
mode: "000644"
owner: root
group: root
content : |
upstream nodejs {
server 127.0.0.1:80;
keepalive 256;
}
server {
listen 8080;
large_client_header_buffers 8 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;

proxy_pass http://nodejs;
proxy_redirect off;

# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
"/opt/elasticbeanstalk/hooks/appdeploy/enact/41_remove_eb_nginx_confg.sh":
mode: "000755"
owner: root
group: root
content : |
mv /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf.old

关于node.js - Elastic Beanstalk 在配置菜单中没有负载均衡器设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47216228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com