Node.js 带有两个元素(node/express API和VueJS应用程序)的nginx重定向到OpenAPI的空白页面

Node.js 带有两个元素(node/express API和VueJS应用程序)的nginx重定向到OpenAPI的空白页面,node.js,nginx,swagger,swagger-ui,openapi,Node.js,Nginx,Swagger,Swagger Ui,Openapi,我正在运行一个使用node.js/express API和vue.js应用程序的服务 该结构用于呈现位于rooturl.com的vue.js应用程序,以及位于rooturl.com/API的API。在express API中,有一个指向OpenAPI/Swagger帮助页面的重定向(我删除了其中的一些其他内容): 当我设置好(见下文)后,我可以让Vue.js应用程序正常工作,API通常工作正常,但通过API重定向到swagger/OpenAPI页面会导致空白页面或nginx错误 我尝试过使用文件

我正在运行一个使用node.js/express API和vue.js应用程序的服务

该结构用于呈现位于
rooturl.com
的vue.js应用程序,以及位于
rooturl.com/API
的API。在express API中,有一个指向OpenAPI/Swagger帮助页面的重定向(我删除了其中的一些其他内容):

当我设置好(见下文)后,我可以让Vue.js应用程序正常工作,API通常工作正常,但通过API重定向到swagger/OpenAPI页面会导致空白页面或nginx错误

我尝试过使用文件所有权和不同的
nginx.conf
配置,但在这一点上我被卡住了。下面是我的conf文件。我已将URL更改为
rooturl.com
。感谢您的帮助

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;
  sendfile        on;
  keepalive_timeout  65;

  server {
      listen      80;
      server_name rooturl.com;
      charset utf-8;
      root    /app/tpvue;
      index   index.html index.htm;
      # Always serve index.html for any request

      location /api {
          proxy_pass http://127.0.0.1:3000;
      }
      location /api/api-docs {
          proxy_pass http://127.0.0.1:3000/api/api-docs;
      }
      location / {
          root /app/tpvue;
          try_files $uri /index.html;
      }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }
}

使用当前设置,转到
rooturl.com/api/api docs
会导致一些502错误,并且yaml文件无法呈现。

在express应用程序中,您使用的是路径
/api docs
,而不是
/api/api docs
。这不是问题吗?当您使用proxy_pass重定向时,您应该使用相对于要重定向到的服务器的url路径。。。
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;
  sendfile        on;
  keepalive_timeout  65;

  server {
      listen      80;
      server_name rooturl.com;
      charset utf-8;
      root    /app/tpvue;
      index   index.html index.htm;
      # Always serve index.html for any request

      location /api {
          proxy_pass http://127.0.0.1:3000;
      }
      location /api/api-docs {
          proxy_pass http://127.0.0.1:3000/api/api-docs;
      }
      location / {
          root /app/tpvue;
          try_files $uri /index.html;
      }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }
}