Rest server and websocket use with elastic layer, java, cannot connect
I am trying to set up nginx routing to be able to use a rest server (using Java Spark) and Websockets (using Netty-socketIO).
It works very well locally, but can't get it to work with aws elastic layer.
I have a Java Spark listening on port 5000 by default from http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html
By default, Elastic Beanstalk configures the nginx proxy to forward requests to your application on port 5000
and it works.
I am listening on port 9000 for Websocket. I changed ELB protocol to TCP.
And yet, from the aws docs:
To extend the default nginx config using elastic beanstalk, add .conf config files to a folder named .ebextensions / nginx / conf.d / in your application source bundle. Beanstalk nginx elastic config will automatically include .conf files in this folder.
which I tried without much success:
server {
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
SocketIO client connection string http://beanstalk-address-here.us-east-1.elasticbeanstalk.com:9000
On the "Network" tab, a request (awaiting a response) before failure.
source to share
One problem is probably that you don't have a properly configured ELB other than connections on port 9000. You must configure the security groups correctly on the ELB to allow connections on non-standard ports:
https://aws.amazon.com/premiumsupport/knowledge-center/elb-connectivity-troubleshooting/
source to share
Why are you using nginx if you are still accessing your application through a non-standard port
Nginx routing usually accepts all connections on one separate port (usually 80/443) and, based on the configuration path, redirects to any specific ip / port
Nginx config file should have these
Nginx listening port
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
}
Redirect list
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;
}
}
Now restart nginx
Your app url is http://beanstalk-address-here.us-east-1.elasticbeanstalk.com:9000
Your redirected url is http://beanstalk-address-here.us-east-1.elasticbeanstalk.com (nginx will listen on port 80 and redirect to application port)
source to share