0
votes

I'm running two Meteor apps on Digital Ocean droplet. Using nginx to reverse proxy. Both are running successfully on non-www domains, but on www.my-domain1.com and www.my-domain2.com are only 'Welcome to nginx on Debian!' pages. I assume it's because in configuration file I use only non-www domain as following:

server {  
 listen 80;
 server_name my-domain1.com;

 location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-For $remote_addr;
 }
}

and the similar, but different domain and port for the second application. I tried to redirect using Digital Ocean tutorial., but it doesn't work and also I should see application working on www domain too.

1

1 Answers

2
votes

The current server is listening on port 80 for any request having the my-domain1.com HOST header.

You'll need first to add www.my-domain1.com and www.my-domain2.com in the server_name line:

server_name my-domain1.com my-domain2.com www.my-domain1.com www.my-domain2.com;

Then restart Nginx. Although some guides will tell you to use *.my-domain1.com *.my-domain2.com in the server_name directive; I'd not do it since that requires more work in the Nginx side. Generally speaking is harder to debug catch-all settings when you're serving more hostnames in the same Nginx server.

Another thing to take into consideration is the upstream server hostname. For instance, if your upstream application is listening to my-domain1.com ONLY; you'll need to make it so all proxyed requests include this domain name; otherwise the upstream application won't serve the request as expected.

You might need to add

proxy_set_header Host my-domain1.com;