首页 > 解决方案 > Nginx proxy_pass 规则不适用于我的角度应用程序

问题描述

以下是在我的 Nginx 服务器中创建的用于指向两个应用程序的 proxy_pass 规则。代理规则适用于默认 URL,但我无法指出在端口 2000 中运行的应用程序。请帮助我找到根本原因。这是由于 URL 中的 # 造成的吗?

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    location /#/login {
        proxy_pass http://3.81.197.217:2000;
    }
    location / {
        proxy_pass http://3.81.197.217;
    }
}

更多细节

  1. http://3.81.197.217:2000是一个运行在 2000 端口的 Angular 应用程序
  2. http://3.81.197.217是在同一个盒子的 80 端口上运行的另一个应用程序。

这两个应用程序都是用 Angular 构建的,并且在 URL 中有 #

标签: nginxnginx-reverse-proxyproxypass

解决方案


我认为最好的方法是使用不同的子域,因为这两个应用程序都有很多路由,所以你的解决方案会产生很多冲突。

中的问题/。试试这个配置它会工作。

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    location /#/login/ {
        proxy_pass http://3.81.197.217:2000/;
    }
    location / {
        proxy_pass http://3.81.197.217/;
    }
}

推荐阅读