I am currently working on setting up multiple APIs on a single VPS and serving them through Nginx. My goal is to have all of them organized in separate sub-locations, as shown in the example below:
For Express remote paths:
[myhost].com/apps/app1/api
[myhost].com/apps/app2/api
And for Express local paths:
localhost:[app1 port]
localhost:[app2 port]
When it comes to Socket.IO, the remote paths are structured like this:
[myhost].com/apps/app1/api/socket.io
[myhost].com/apps/app2/api/socket.io
While the local paths look like:
localhost:[app1 port]/socket.io
localhost:[app2 port]/socket.io
Express is functioning properly, and I can access it locally using the following command:
curl -ivL http://localhost:[app1 port]
However, due to the 'path' property in Socket.IO, Socket.IO responses are only accessible at:
curl -ivL http://localhost:[app1 port]/apps/app1/api/socket.io/?EIO=4
Without the 'path' specified, remote access to Socket.IO becomes unavailable.
const ioServer = new socketIo.Server(httpServer, {
...
path: "/apps/app1/api/socket.io", <---- this 'path' property
});
In terms of Nginx configuration:
......
location /apps {
index _;
autoindex on;
location /apps/app1/api/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://localhost:[app1 port];
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /apps/app1 {
index index.html;
}
....
I am seeking a solution to remove the /apps/app1/api part from the localhost Socket.IO setup without compromising the ability for remote access. Any suggestions would be greatly appreciated. Thank you.