我正在尝试将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?
最佳答案