问题描述
我正在运行使用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 (将#修改为@)