ElasticBeanstalk上的Websockets给出了404

时间:2015-05-17 19:09:12

标签: nginx jar websocket elastic-beanstalk

我正在尝试将websocket服务器部署到Elastic Beanstalk。 我有一个包含nginx和jar服务器的Docker容器,nginx只是进行转发。 nginx.conf是这样的:

listen 80;
location /ws/ {             # <-- this part only works locally
    proxy_pass http://127.0.0.1:8090/;     # jar handles websockets on port 8090
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
location / {                     # <-- this part works locally and on ElasticBeanstalk
    proxy_pass http://127.0.0.1:8080/;   # jar handles http requests on port 8080
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
}

我可以在本地运行这个docker并且一切正常 - 提供http请求,我可以使用ws://localhost:80/ws/连接websockets但是,当我部署到Elastic Beanstalk时,http请求仍然可以,但是尝试连接websockets在ws://myjunk.elasticbeanstalk.com:80/ws/上出现404错误。我是否需要其他东西来允许Elastic Beanstalk上的websockets?

1 个答案:

答案 0 :(得分:3)

好的,让它运转起来。我需要ElasticBeanstalk负载均衡器来使用TCP而不是HTTP。

要从AWS控制台执行此操作(如2015年5月16日所述),请转到ElasticBeanstalk环境,在左侧菜单中选择“配置”,在“网络层”下,有一个“负载平衡”窗格。单击其齿轮,然后您可以将负载平衡器协议从http更改为tcp。