So I am having three node
apps on the same server and they are all started to different localhost's ports. With that I am trying to do kind of a router that make a proxy for every apps and then put this proxy in a virtual host. Currently I am testing this on my local network but it will be on a "real" server in the future.
Just to make an exemple, my router is on 0.0.0.0:3000
and one of my apps is on 0.0.0.0:3001
. So here is how it looks like if I try to make a proxy to the app on the router :
app.use('/*', proxy({ target: 'http://0.0.0.0:3001', changeOrigin: true }));
It works when I am going on http://localhost:3000
. But it is not in a virtual host, so here it is :
app.use('/*',
vhost('test.*', proxy({ target: 'http://0.0.0.0:3001', changeOrigin: true }))
);
It still works but only on http://test.localhost:3000
.
If I try to access it via my IP (mydomain.com
is mapped to my IP in my hosts
file, you can see it down bellow) : http://test.mydomain.com
express return me Cannot GET /
. And even on mydomain.com
it works well without the virtual host.
Here is my hosts
file (I am not sure if it is safe to share this IP so I am masking a part of it) :
192.168.*.*:3000 mydomain.com
Packages I use : http-proxy-middleware, vhost, express.
My final question is : how could I make this virtual host works on another IP / domain than localhost
?
UPDATE :
I don't know if this information can be usefull, but even if I put www.google.com
in my proxy with the virtual host, it doesn't works.