Issue
I'm trying to set up nginx so I can have my domain, domain.com
run by a node web app on port 3000, and the subdomain dev.domain.com
run by a second node web app on port 3001. When I run this configuration domain.com
is connected to the right port, but dev.domain.com
just gives a page that says the server can't 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 at dev.domain.com
. Based on this it seems like the apps are running fine on the right ports, and I'm just not routing the subdomain correctly.
Code
I edited /etc/nginx/sites-available/default
directly so it has:
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;
}
}
Other than that file everything else is a fresh install
My logic
I'm very new to nginx but this seems like any requests for domain.com
would get sent to port 3000, and requests for dev.domain.com
would go to 3001.
Any help or critique of what I've done so far would be greatly appreciated!
Above setup works fine. My issue was with DNS records - I added an A record directing dev.domain.com
to the IP address of the server I'm running the node apps on.
Faced same issue and solved it by creating file from root user:
drwxr-xr-x 6 gitlab-runner gitlab-runner 4096 Sep 12 06:56 .
drwxr-xr-x 4 root root 4096 Sep 12 06:57 ..
-rw-r--r-- 1 root root 11 Sep 12 06:54 .env
-rw-rw-r-- 1 gitlab-runner gitlab-runner 599 Sep 12 06:56 app.js
If you will delete all files and directories in this folder from gitlab-runner
with rm -Rf
command it will delete all files except .env
This is just quick workaround may be will be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With