我正在尝试在我的Elastic Beanstalk应用程序上启用websocket,但是在我按照此处的说明(https://mitchellsimoens.com/websockets-behind-elastic-beanstalk/)后,我发现我的应用程序的运行状况已降级。这可能是因为我未能在本说明书中提到的配置菜单中找到负载均衡器设置。
以下是配置菜单的屏幕截图:
显然,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";
}
}
答案 0 :(得分:1)
Scaling > Single instance
类型的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