I have multiple node instances running each on a different port. (8000, 8001, etc.) I also have nginx running on port 80. What I am trying to do is allow a user to enter my site via a single domain name, and then via different urls be able to access a different node server.
Currently everything works as following
http://example.com:8000/index.html (This is one node server running a site) http://example.com:8001/index.hmtl (this is another node server running a different site) What I want to be able to do is allow the user to type in a url path and auto direct them to the correct site without them having to specify the port. So for instance:
http://example.com/site1/inedx.html (This is one node server running a site at port 8000) http://example.com/site2/index.html (this is another node server running a different site at port 8001) I have been trying to achieve this with nginx proxy_pass rules but am having trouble getting it to work. Essentially nginx reroutes to the correct express server, but then all my routing in the express app breaks because it lacks the port.
So when I go to http://example.com/site1/index.html it takes me to http://example.com/index.html. Any help would be greatly appreciated. I have pasted the relevant portions of the nginx.conf and and example express route below.
nginx.conf
server { listen 80; server_name 11.11.11.111; root /home/ubuntu; location /site1/ { proxy_pass http://11.11.11.111:8000/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $proxy_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://11.11.11.111:8000/; proxy_redirect http://11.11.11.111/* http://11.11.11.111:8000/*; } location /site2/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $proxy_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://11.11.11.111:8001/; proxy_redirect http://11.11.11.111/* http://11.11.11.111:8001/*; } } app.js
app.get('/', function(req, res){ res.redirect('/index.html'); });
ip:portit's running on ... How could it work for links anyway ? You won't rewrite them with nginx too do you ?