使用 nginx proxy_pass 在不同的端口上托管 2 个应用程序

使用 nginx proxy_pass 在不同的端口上托管 2 个应用程序

为什么proxy_pass http://backends/;位置下的/textcat会将我带到服务器的根目录(localhost:8081)并且proxy_pass http://backends;(没有尾随的 /)会将我带到(看似)localhost:8081/textcat

8081我正在尝试托管两个在服务器上本地运行的应用程序。这两个应用程序在端口和上运行8082。我想8081通过位置/textcat8082通过访问应用程序/ner。我能够使用以下配置做到这一点。但我不太明白为什么这样做有效?

upstream backends {
    server localhost:8081; # change to the port the webapp is listening on.
}


upstream backends_NER {
    server localhost:8082; # change to the port the webapp is listening on.
}

server {
    listen 443 ssl;
    server_name "";
    ...SSL Stuff...

    location = /textcat {
        proxy_pass http://backends/;

  }
    location /ner {
        proxy_pass http://backends_NER/;# This seems to work because of the trailing slash. Since the http_referrer is /ner our proxy path has to have the trailing /
  }
# have to redirect on a any location request, and if the referrer is /textcat do localhost:8081
    location / {
    if ($http_referer ~* (/textcat) ) {
        proxy_pass http://localhost:8081;
    }
    if ($http_referer ~* (/ner) ) {
        proxy_pass http://localhost:8082;
    }
  }
}

相关内容