I have 2 different ( Node & Angular ) applications running under a domain. I am trying to configure nginx in way to serve like, whenever anyone access "domain.com" it should serve the node app running on port 4200 and if someone access "domain.com/admin" it should serve the contents from Angular app. Below is my nginx configuration.
server {
listen 80;
listen [::]:80;
server_name domain.com
}
server {
listen 443 default_server ssl;
ssl on;
server_name domain.com;
root /home/domain/public_html/angular/dist;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://127.0.0.1:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location /admin {
try_files $uri /index.html;
}
}
The problem I am facing now is all the requests including /admin
is getting proxy passed. Is there any way I can restrict the /admin
requests to not get proxy passed? Below is the nginx log.
connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: domain.com, request: "GET /admin HTTP/1.1", upstream: "http://127.0.0.1:4200/admin", host: "domain.com"
Can someone please shed some light to get this resolved?