Configure nginx for two node applications, with one on a subdomain

Question

I am trying to configure nginx to have my own domain domain.comthat is launched by the node web application on port 3000, and the subdomain dev.domain.comis executed by the second node web application on port 3001. When I run this configuration, it domain.comconnects to the correct port, but dev.domain.comjust gives a page in which states that the server cannot be reached.

Edit: If I go to IP_ADDRESS:3000, I get the same content as domain.com, but if I go to IP_ADDRESS:3001, I get what should be in dev.domain.com. Based on this, it seems that the applications are working fine on the correct ports, and I'm just not properly routing the subdomain.

the code

I edited /etc/nginx/sites-available/defaultdirectly, so he:

server {
    listen 80 default_server;
    server_name domain domain.com www.domain.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}
server {
    listen 80;
    server_name dev.domain dev.domain.com www.dev.domain.com;
    location / {
        proxy_pass http://127.0.0.1:3001;
    }
}

Except this file everything else is a new version

My logic

I am very new to nginx, but it looks like any requests for domain.comwill be sent to port 3000, and requests for dev.domain.comwill go up to 3001.

Any help or criticism of what I have done so far will be greatly appreciated!

+4
source share
1 answer

The installation works fine. My problem was with the DNS records - I added an A record directing dev.domain.comto the server IP address. I am running node applications.

+2
source

Source: https://habr.com/ru/post/1648598/


All Articles