We have and elastic beanstalk instance, we have some rest services and socket.io too. express is being started ad port 80. I started socket.io at 3001. but unable to connect this socket. I have also switched off the proxy, from nginx to off. code for socket is as below
我们有和弹性豆茎实例,我们有一些休息服务和插座。io。快线正从80端口开始。我开始套接字。io,享年3001岁。但是无法连接这个插座。我也关掉了代理,从nginx到off。套接字的代码如下。
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io')(server), //make sockets
port = 3001;//port for socket
//initiate server
server.listen(port, function () {
console.log('Socket.io listening at port %d', port);
});
4 个解决方案
#1
7
By default an elastic beanstalk instance has an nginx proxy in front of it that is not configured to allow webSockets. You can either turn the proxy off or you can configure the nginx instance to support webSockets.
在默认情况下,弹性beanstalk实例前面有一个nginx代理,但未配置为允许webSockets。您可以关闭代理,也可以配置nginx实例以支持webSockets。
Here's an article that describes how to enable support for webSockets in the proxy.
这里有一篇文章描述了如何在代理中支持webSockets。
And, here are two articles that describe disabling the proxy entirely here and here.
这里有两篇文章描述了完全在这里和这里禁用代理。
And, even a * question/answer on the same topic:
甚至是关于同一主题的*问题/答案:
Websockets with socket.io on AWS Elastic Beanstalk
Websockets与套接字。我用的是弹性豆茎
#2
0
I can not say for sure but I think you don't have port 3001 open on your security groups. You must allow traffic on port 3001 for ec2 sg of your eb app so that ELB of your elb app has access. Also, make sure you configure SG of ELB so that anyone from internet can access the socket.io port on the EC2 instances via ELB. However, you will need to use TCP based listener with proxy protocol enabled for socket.io to work well. I have not checked this but I don't think you can configure port 3001 on listener section. In such case, you can use nginx and configure upstream and location blocks so that you send requests to correct upstream. You can have a look on .ebextensions based configurations so that you can replace nginx configurations during deploy appropriately. The downside of this is that your script might need change along with the upgrades of elastic beanstalk solution stack.
我不能肯定地说,但是我认为您的安全组没有3001端口。您必须允许您的eb应用程序的ec2 sg上的端口3001上的流量,以便您的ELB应用程序的ELB能够访问。另外,确保您配置了ELB的SG,以便internet上的任何人都可以访问套接字。通过ELB在EC2实例上的io端口。但是,您需要使用为socket启用了代理协议的基于TCP的侦听器。io工作。我没有检查这个,但是我认为您不能在监听器部分配置端口3001。在这种情况下,可以使用nginx并配置上游和位置块,以便向上游发送请求以纠正错误。您可以查看基于. ebex紧张的配置,这样您就可以在适当的部署期间替换nginx配置。这样做的缺点是,随着弹性beanstalk解决方案堆栈的升级,您的脚本可能需要更改。
#3
0
Create a new config file in .ebextensions.
在. ebextense创建一个新的配置文件。
Add this:
添加:
container_commands:
enable_websockets:
command: |
sed -i '/\s*proxy_set_header\s*Connection/c \
proxy_set_header Upgrade $http_upgrade;\
proxy_set_header Connection "upgrade";\
' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
#4
-3
It was issue with security restrictions. otherwise code works fine. thanks for help guys.
这是安全限制的问题。否则代码工作正常。谢谢你的帮助。
#1
7
By default an elastic beanstalk instance has an nginx proxy in front of it that is not configured to allow webSockets. You can either turn the proxy off or you can configure the nginx instance to support webSockets.
在默认情况下,弹性beanstalk实例前面有一个nginx代理,但未配置为允许webSockets。您可以关闭代理,也可以配置nginx实例以支持webSockets。
Here's an article that describes how to enable support for webSockets in the proxy.
这里有一篇文章描述了如何在代理中支持webSockets。
And, here are two articles that describe disabling the proxy entirely here and here.
这里有两篇文章描述了完全在这里和这里禁用代理。
And, even a * question/answer on the same topic:
甚至是关于同一主题的*问题/答案:
Websockets with socket.io on AWS Elastic Beanstalk
Websockets与套接字。我用的是弹性豆茎
#2
0
I can not say for sure but I think you don't have port 3001 open on your security groups. You must allow traffic on port 3001 for ec2 sg of your eb app so that ELB of your elb app has access. Also, make sure you configure SG of ELB so that anyone from internet can access the socket.io port on the EC2 instances via ELB. However, you will need to use TCP based listener with proxy protocol enabled for socket.io to work well. I have not checked this but I don't think you can configure port 3001 on listener section. In such case, you can use nginx and configure upstream and location blocks so that you send requests to correct upstream. You can have a look on .ebextensions based configurations so that you can replace nginx configurations during deploy appropriately. The downside of this is that your script might need change along with the upgrades of elastic beanstalk solution stack.
我不能肯定地说,但是我认为您的安全组没有3001端口。您必须允许您的eb应用程序的ec2 sg上的端口3001上的流量,以便您的ELB应用程序的ELB能够访问。另外,确保您配置了ELB的SG,以便internet上的任何人都可以访问套接字。通过ELB在EC2实例上的io端口。但是,您需要使用为socket启用了代理协议的基于TCP的侦听器。io工作。我没有检查这个,但是我认为您不能在监听器部分配置端口3001。在这种情况下,可以使用nginx并配置上游和位置块,以便向上游发送请求以纠正错误。您可以查看基于. ebex紧张的配置,这样您就可以在适当的部署期间替换nginx配置。这样做的缺点是,随着弹性beanstalk解决方案堆栈的升级,您的脚本可能需要更改。
#3
0
Create a new config file in .ebextensions.
在. ebextense创建一个新的配置文件。
Add this:
添加:
container_commands:
enable_websockets:
command: |
sed -i '/\s*proxy_set_header\s*Connection/c \
proxy_set_header Upgrade $http_upgrade;\
proxy_set_header Connection "upgrade";\
' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
#4
-3
It was issue with security restrictions. otherwise code works fine. thanks for help guys.
这是安全限制的问题。否则代码工作正常。谢谢你的帮助。