【问题标题】:Swagger Nginx flask-restplusSwagger Nginx 烧瓶-restplus
【发布时间】:2018-06-28 18:40:04
【问题描述】:

我正在尝试让 Flask-RESTplus 的 Swagger UI 在使用 Nginx 作为代理的服务器上运行。

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

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

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;
}

但是,当我转到http://ServerIP/api 时,我只看到一个空白页。在 Chrome 开发工具中有一个错误:

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

指的是:

<script src="/swaggerui/swagger-ui-bundle.js"></script>
<script src="/swaggerui/swagger-ui-standalone-preset.js"></script>
<script type="text/javascript">
    window.onload = function() {
        const ui = window.ui = new SwaggerUIBundle({

但我可以到达(200 OK,提供 javascript 文件) http://ServerIP/swaggerui/swagger-ui-bundle.jshttp://ServerIP/swaggerui/swagger-ui-standalone-preset.js

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

【问题讨论】:

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


    【解决方案1】:

    类似问题: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;,但如果您希望连接比平时更长(速度或大小),则不建议这样做。

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 2014-07-02
      相关资源
      最近更新 更多