I have a game running on my server. When a user requests it, a new process on my server is started and starts to listen for a websocket connection on a random port in the range 8001-8100.
On the client i want to connect to the game.
var port = 8044; // <- Client is given this number when creating a new game
connection = new WebSocket("wss://XXX/websocket?port=" + port);
My server is a nginx reverse proxy. I want to do something like this: (I need a working replacement for it, the below should illustrate the point.)
server {
...
location /websocket/ {
if(isNumber($port) && $port <= 8100 && $port >= 8001 {
proxy_pass http://localhost:$port;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
} }
Reason for those reverse proxy shenanigans is to be able to use the default 443 port, meaning clients won't have firewall problems. Othwerwise I would just directly connect to the correct port from the client.
Any ideas?