I'm trying to run a simple websocket echo application on Elastic Beanstalk. But if I run it I'm getting an error 400 on the Socket Upgrade from Tomcat, but this just happens on port 80 if I pass port 8080 thought the loadbalancer I can access the websocket without the error 400 on socket upgrade (on port 8080). Port 8080 and Port 80 are both on TCP not HTTP.
我正在尝试在弹性Beanstalk上运行一个简单的websocket echo应用程序。但是如果我运行它,我在从Tomcat的套接字升级中会得到一个错误400,但是如果我通过端口8080,就会在端口80上发生这种情况,因为负载均衡器认为我可以在套接字升级(端口8080)时访问websocket,而不会出现错误400。端口8080和端口80都在TCP上,而不是HTTP上。
My question is who is doing the translation from 80 to 8080 as the default configuration on the loadbalancer just pass traffic from 80 to 80. The translation has to be on the EC2 instance. IPTables? In this translation something goes wrong.
我的问题是,谁在做从80到8080的转换,作为负载均衡器上的默认配置,只是将流量从80传递到80。转换必须在EC2实例上。IPTables吗?在这个翻译中,出了问题。
It would be nice to get some inforamtion from amazon on how this traffic is routet.
如果能从亚马逊得到一些关于流量的惯例的信息就好了。
1 个解决方案
#1
16
The solution is to configure the Loadbalacer to connect directly to the Tomcat:
解决方案是配置Loadbalacer直接连接到Tomcat:
Resources:
AWSEBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Security group to allow HTTP, SSH and 8080 for all"
SecurityGroupIngress:
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "80", ToPort: "80"}
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "8080", ToPort: "8080"}
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "22", ToPort: "22"}
AWSEBLoadBalancer:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
Listeners:
- {LoadBalancerPort: 443, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "SSL", SSLCertificateId: "arn:aws:iam::9999999999999:server-certificate/sslcert"}
- {LoadBalancerPort: 80, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "TCP"}
AppCookieStickinessPolicy:
- {PolicyName: "lb-session", CookieName: "lb-session"}
HealthCheck:
HealthyThreshold: "3"
Interval: "30"
Target: "HTTP:8080/ping.html"
Timeout: "5"
UnhealthyThreshold: "5"
- Create a folder called .ebextensions in the WEB-INF folder Maybe in newer Version the .ebextensions has to be in the root folder, can somebody confirm this?
- 在WEB-INF文件夹中创建一个名为。ebextense的文件夹,也许在更新的版本中。
- Create a file called websocket.config in this folder with the content from above
- 创建一个名为websocket的文件。在这个文件夹中配置上面的内容
- Deploy the application
- 部署应用程序
- Rebuild the environment
- 重建环境
For a setup without SSL remove this:
对于一个没有SSL的设置,请删除以下内容:
- {LoadBalancerPort: 443, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "SSL", SSLCertificateId: "arn:aws:iam::9999999999999:server-certificate/sslcert"}
Or replace Apache by Nginx and configure Niginx to support WebSocket
或者用Nginx替换Apache并配置Niginx以支持WebSocket
#1
16
The solution is to configure the Loadbalacer to connect directly to the Tomcat:
解决方案是配置Loadbalacer直接连接到Tomcat:
Resources:
AWSEBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Security group to allow HTTP, SSH and 8080 for all"
SecurityGroupIngress:
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "80", ToPort: "80"}
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "8080", ToPort: "8080"}
- {CidrIp: "0.0.0.0/0", IpProtocol: "tcp", FromPort: "22", ToPort: "22"}
AWSEBLoadBalancer:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
Listeners:
- {LoadBalancerPort: 443, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "SSL", SSLCertificateId: "arn:aws:iam::9999999999999:server-certificate/sslcert"}
- {LoadBalancerPort: 80, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "TCP"}
AppCookieStickinessPolicy:
- {PolicyName: "lb-session", CookieName: "lb-session"}
HealthCheck:
HealthyThreshold: "3"
Interval: "30"
Target: "HTTP:8080/ping.html"
Timeout: "5"
UnhealthyThreshold: "5"
- Create a folder called .ebextensions in the WEB-INF folder Maybe in newer Version the .ebextensions has to be in the root folder, can somebody confirm this?
- 在WEB-INF文件夹中创建一个名为。ebextense的文件夹,也许在更新的版本中。
- Create a file called websocket.config in this folder with the content from above
- 创建一个名为websocket的文件。在这个文件夹中配置上面的内容
- Deploy the application
- 部署应用程序
- Rebuild the environment
- 重建环境
For a setup without SSL remove this:
对于一个没有SSL的设置,请删除以下内容:
- {LoadBalancerPort: 443, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "SSL", SSLCertificateId: "arn:aws:iam::9999999999999:server-certificate/sslcert"}
Or replace Apache by Nginx and configure Niginx to support WebSocket
或者用Nginx替换Apache并配置Niginx以支持WebSocket