昂首阔步Nginx烧瓶-restplus

时间:2018-06-28 18:40:05

标签: nginx flask swagger swagger-ui flask-restplus

我正在尝试从Flask-RESTplus获取Swagger UI,使其在使用Nginx作为代理的服务器上工作。

Swagger在/ api上投放,并使用http://localhost:5000/api在本地工作。我正在尝试将Nginx设置为代理,以便可以转到http://ServerIP/api并查看Swagger UI。

我已经为Nginx尝试了许多配置,目前已经

    <div id="includedContent"></div>

但是,我刚进入http://ServerIP/api时看到空白页。在Chrome开发者工具中存在错误:

location /api {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://localhost:5000;
        proxy_redirect off;
        proxy_intercept_errors on;
        proxy_http_version 1.1;
}

指的是:

Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload (api:75)

但是我能够到达(200行,提供了javascript文件) http://ServerIP/swaggerui/swagger-ui-bundle.js http://ServerIP/swaggerui/swagger-ui-standalone-preset.js

任何想法可能是什么问题?

1 个答案:

答案 0 :(得分:0)

相似的问题:Server response gets cut off half way through

在发送大型上游文件时,Nginx需要具有写入临时文件夹的权限。通常,您会在/var/log/nginx/error.log中看到它,例如

2018/06/28 16:34:48 [crit] ... open() "<tmp folder>/x/y/00000000z" failed (13:
Permission denied) while reading upstream, <request info...>

要解决此问题,您可以使用nginx:nginx(除非您已手动更改用户),例如sudo chown -R nginx:nginx /var/lib/nginx。如果权限不小于7xx,则可能需要更改它,但这不应该成为问题。

或者,您可以设置proxy_buffering off;,但是如果您希望连接比平时更长(速度或大小),则不建议这样做。

相关问题