Running a websocket server and a http server on the same server
A terribly written question, but the term I was looking for was reverse proxy.
Basically, just like how nginx can forward different request to several instances of the web app based on the path or hostname, it can also be configured to "forward" the request to a websocket server instance. e.g.:
location /socket {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
upstream websocket{
server localhost:8000;
}
map $http_upgrade $connection_upgrade {
default Upgrade;
'' close;
}
HTTP requests to http://hostname
will be served the usual html page, while websocket connection to wss://hostname/socket
will be forwarded to the websocket instance on the same server listening on port 8000.
A server can't have two different software listening on the same port/IP address. Otherwise, how would the traffic be routed to Application XYZ if multiple applications could be binding to the same port?
You can learn more about ports from Port (computer networking)
What you need to do is either one of the following options:
- Use a different port for one of the two application and allow that through your firewall.
- Use two different IP addresses - and bind each application to their respective IP addresses.
Your firewall just need to be configured according to what you set up.