I've got two IPs associated with my VPS, and am trying to set this up to serve two node apps. Here's my configuration:
In /etc/nginx/sites-enabled/domain1:
upstream app_domain1 {
server 127.0.0.1:4000;
}
server {
listen 0.0.0.0:80;
server_name IP1.xxx.xxx.xxx;
access_log /var/log/nginx/domain1.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nninx-Proxy true;
proxy_pass http://app_domain1/;
proxy_redirect off;
}
}
And in /etc/nginx/sites-enabled/domain2
upstream app_domain2 {
server 127.0.0.1:3000;
}
server {
listen 0.0.0.0:80;
server_name IP2.xxx.xxx.xxx;
access_log /var/log/nginx/domain2.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nninx-Proxy true;
proxy_pass http://app_domain2/;
proxy_redirect off;
}
}
And in /etc/nginx/sites-enabled, I ran:
ln -s /etc/nginx/sites-available/domain1 domain1
ln -s /etc/nginx/sites-available/domain2 domain2
Now, when I go to /var/www/domain1 and run "node app.js" on the correct port, I can visit the relevant IP address and see the app running, but the same is not true for domain2 (I checked that it's running on the correct port for this config. The request just times out - no response at all.
So how can I troubleshoot this?
Update:
If I go to the ports directly, I see both apps available on both IPs, so:
IP1.xxx.xxx.xxx:4000 gives me the app for domain1
IP1.xxx.xxx.xxx:3000 gives me the app for domain2
and
IP2.xxx.xxx.xxx:4000 gives me the app for domain1
IP2.xxx.xxx.xxx:3000 gives me the app for domain2
So it's treating each IP address as the same.
server_name accepts only domains but not IP addresses.
You have typo mistake in proxy headers, change this:
proxy_set_header X-Nninx-Proxy true;
with this:
proxy_set_header X-NginX-Proxy true;