使用Tomcat 7的WebSocket在AWS弹性魔豆 [英] Websocket with Tomcat 7 on AWS Elastic Beanstalk

查看:340
本文介绍了使用Tomcat 7的WebSocket在AWS弹性魔豆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行弹性魔豆一个简单的WebSocket回声应用程序。但是,如果我运行它,我就从Tomcat的插槽升级得到一个错误400,但是这只是发生在端口80,如果我通过8080端口以为负载均衡器,我可以访问的WebSocket没有错误400插槽升级(在端口8080 )。 8080端口和80端口都在TCP不是HTTP。

我的问题是谁在做这些翻译从80到8080的负载均衡器的默认配置只是通过流量从80到80的转换必须在EC2实例。 IPTables的?在这个翻译出了问题。

这将是很好得到亚马逊的一些inforamtion关于如何交通routet。

解决方案

解决的办法是配置Loadbalacer直接连接到Tomcat的:

 资源:
  AWSEBSecurityGroup:
    类型:AWS :: EC2 :: SecurityGroup
    属性:
      GroupDesc​​ription:安全组允许HTTP,SSH和8080为人人
      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:
    类型:AWS :: ElasticLoadBalancing ::负载平衡器
    属性:
      听众:
         -  {LoadBalancerPort:443,InstanceProtocol:TCP,InstancePort:8080,协议:SSL,SSLCertificateId:ARN:AWS:IAM :: 9999999999999:服务器证书/的sslcert}
         -  {LoadBalancerPort:80,InstanceProtocol:TCP,InstancePort:8080,协议:TCP}
      AppCookieStickinessPolicy:
         -  {policyname:表示LB-会议,CookieName:LB-会议}
      健康检查:
        HealthyThreshold:3
        间隔时间:30
        目标:HTTP:8080 / ping.html
        超时:5
        UnhealthyThreshold:5
 

  1. 创建一个文件夹中的WEB-INF文件夹,名为.ebextensions
  2. 从上面的内容创建该文件夹中名为websocket.config文件
  3. 在部署应用程序
  4. 重建环境

对于没有SSL一个安装删除此:

   -  {LoadBalancerPort:443,InstanceProtocol:TCP,InstancePort:8080,协议:SSL,SSLCertificateId:ARN:AWS:IAM :: 9999999999999:服务器证书/的sslcert}
 

或更换由Apache通过<一个href="http://www.nczonline.net/blog/2012/09/14/replacing-apache-with-nginx-on-elastic-beanstalk/">Nginx并配置Niginx支持的WebSocket

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.

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.

解决方案

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"

  1. Create a folder called .ebextensions in the WEB-INF folder
  2. Create a file called websocket.config in this folder with the content from above
  3. Deploy the application
  4. Rebuild the environment

For a setup without SSL remove this:

 - {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

这篇关于使用Tomcat 7的WebSocket在AWS弹性魔豆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆