Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

Nginx conditional proxy pass configuration

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?

question from:https://stackoverflow.com/questions/65952966/nginx-conditional-proxy-pass-configuration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...