Reputation: 11
I have two different nodejs + expressjs applications with different SSL certificates. I got another IP address for my second app. I have only one port enabled i.e 443. When I run first application it runs successfully, but when I try to run second one it trows port already in use error. Please note I am running both application on different IP addresses.
Upvotes: 1
Views: 211
Reputation:
This has nothing to do with the number of interfaces/IP addresses you use. A port on a machine can only be used once. In this case, your first application already listens exclusively to it.
The best way is to use a web server or reverse proxy (e.g. HAProxy, nginx, Apache) listening on all interfaces to handle incoming requests on port 443 and forward the traffic to your applications based on the IP address – or even better (sub)domain name – of the request. Then you can run both applications on a separate port > 1024 that doesn't require root rights to bind (which is also a security issue):
Example:
Request to IP 10.1.10.1 → +---------------------+ → Forwarded to app 1:80441
| Reverse Proxy:443 |
Request to IP 10.1.10.2 → +---------------------+ → Forwarded to app 2:80442
Upvotes: 2