我正在尝试将nginx路由配置为能够同时使用rest服务器(使用Java )和Websockets (使用Netty-socketIO)。
它在本地确实工作得很好,但是不能让它在aws弹性豆杆上工作。
我让Java监听端口5000,这是来自http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html的缺省值
默认情况下,弹性Bean秸秆将nginx代理配置为在端口5000上将请求转发给应用程序。
而且这很管用。
我在端口9000上监听Websocket。我确实把ELB协议改成了TCP。
仍然来自aws文档:
要扩展ElasticBean秸秆的默认nginx配置,请将.conf配置文件添加到应用程序源包中的一个名为.eb扩展名/nginx/.conf.d/的文件夹中。弹性豆柄的nginx配置自动包含此文件夹中的.conf文件。
我试过但没有成功:
server {
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}SocketIO-客户端连接字符串http://beanstalk-address-here.us-east-1.elasticbeanstalk.com:9000
在“网络”选项卡中,请求在失败之前(挂起)一段时间。
发布于 2017-04-06 23:09:48
一个可能的问题是,除了端口9000上的连接之外,您的ELB没有正确配置。必须正确配置ELB上的安全组,以便允许非标准端口上的连接:
https://aws.amazon.com/premiumsupport/knowledge-center/elb-connectivity-troubleshooting/
发布于 2017-04-12 08:59:03
如果您仍然通过非标准端口访问应用程序,为什么要使用nginx?
Nginx路由通常接受单个端口中的所有连接(通常为80/443),并且基于配置路径,它将重定向到任何特定的ip/端口。
您的nginx配置文件本质上应该有以下内容
Nginx监听端口
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
}重定向列表
server{
....
location / {
proxy_pass http://<your-app-ip>:<your-app-port>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}现在重新启动nginx
您的应用程序url是http://beanstalk-address-here.us-east-1.elasticbeanstalk.com:9000
您的重定向url是http://beanstalk-address-here.us-east-1.elasticbeanstalk.com (nginx将监听端口80并重定向到您的应用程序端口)
https://stackoverflow.com/questions/43190535
复制相似问题