AWS Elastic Beanstalk 上带有 Tomcat 7 的 Websocket

编程入门 行业动态 更新时间:2024-10-27 05:25:36
本文介绍了AWS Elastic Beanstalk 上带有 Tomcat 7 的 Websocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 Elastic Beanstalk 上运行一个简单的 websocket echo 应用程序.但是,如果我运行它,我会在 Tomcat 的套接字升级上收到错误 400,但是如果我通过端口 8080,这只会发生在端口 80 上,认为负载均衡器我可以访问 websocket,而不会在套接字升级时出现错误 400(在端口 8080 上)).端口 8080 和端口 80 都在 TCP 而非 HTTP 上.

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.

我的问题是谁在做从 80 到 8080 的转换,因为负载均衡器上的默认配置只是将流量从 80 传递到 80.转换必须在 EC2 实例上进行.IP表?在这个翻译中出了点问题.

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.

如果能从亚马逊获得一些有关此流量如何路由的信息会很好.

It would be nice to get some inforamtion from amazon on how this traffic is routet.

推荐答案

解决方案是配置Loadbalacer直接连接Tomcat:

The solution is to configure the Loadbalacer to connect directly to the 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"

  • 在WEB-INF文件夹中创建一个名为.ebextensions的文件夹也许在较新的版本中 .ebextensions 必须在根文件夹中,有人可以确认吗?
  • 在此文件夹中创建一个名为 websocket.config 的文件,其中包含上述内容
  • 部署应用程序
  • 重建环境
  • 对于没有 SSL 的设置,请删除此:

    - {LoadBalancerPort: 443, InstanceProtocol: "TCP", InstancePort: 8080, Protocol: "SSL", SSLCertificateId: "arn:aws:iam::9999999999999:server-certificate/sslcert"}

    或者用 Nginx 并配置 Niginx 以支持 WebSocket

    Or replace Apache by Nginx and configure Niginx to support WebSocket

    更多推荐

    AWS Elastic Beanstalk 上带有 Tomcat 7 的 Websocket

    本文发布于:2023-11-15 07:53:55,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1592561.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Elastic   AWS   Beanstalk   Websocket   Tomcat

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!