我正在尝试将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 /连接websocket.但是,当我部署到Elastic Beanstalk时,http请求仍然可以,但是尝试在ws://myjunk.elasticbeanstalk.com:80 / ws /上连接websockets会出现404错误.我是否需要其他东西才能在Elastic Beanstalk上允许websocket?
最佳答案
好吧,让它正常工作.我需要ElasticBeanstalk负载平衡器以使用TCP而不是HTTP.
要从AWS控制台(如2015年5月16日所述)执行此操作,请转到您的ElasticBeanstalk环境,在左侧菜单中选择“配置”,在“网络层”下,有一个“负载平衡”窗格.单击其齿轮,然后可以将负载均衡器协议从http更改为tcp.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。