Nginx 条件代理传递配置

Nginx 条件代理传递配置

我有两个不同的 (Node 和 Angular) 应用程序在同一个域下运行。我尝试配置 nginx 以便提供以下服务:每当有人访问“domain.com”时,它都应该为在端口 4200 上运行的节点应用程序提供服务;如果有人访问“domain.com/admin”,它应该为 Angular 应用程序的内容提供服务。以下是我的 nginx 配置。

 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;
    }
    }

我现在面临的问题是所有请求都/admin通过代理。有什么方法可以限制/admin请求不通过代理?以下是 nginx 日志。

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"

有人可以解释一下如何解决这个问题吗?

相关内容