如何解决具有两个元素node / express API和VueJS应用的nginx重定向到OpenAPI的空白页面
我正在运行使用node.js / express API和vue.js应用程序的服务。
该结构旨在在rooturl.com
处渲染vue.js应用程序,在rooturl.com/api
处渲染API。在express API中,可以重定向到OpenAPI / Swagger帮助页面(我在那里删除了一些其他内容):
var swaggerUi = require('swagger-ui-express'),swaggerDocument = YAML.load('./swaggerdocs.yaml');
var options = {
swaggerUrl: 'http://rooturl.com/api-docs',customCssUrl: '/custom.css'
}
app.use('/api-docs',swaggerUi.serve,swaggerUi.setup(swaggerDocument,options));
app.all('*',function(req,res) {
res.redirect('/api-docs');
});
当我进行设置(见下文)时,我可以使Vue.js应用程序正常工作,并且该API通常可以正常工作,但是通过API重定向到swagger / OpenAPI页面会导致空白页面或nginx错误。
我尝试使用文件所有权和不同的nginx.conf
配置,但是到现在为止,我陷入了困境。下面是我的配置文件。我已将网址更改为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文件无法呈现。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。