繁体   English   中英

使用 uwsgi 和 nginx 在部署中显示 flask-restx 的 Swagger UI 时出错

[英]Error displaying Swagger UI of flask-restx in Deployment using uwsgi and nginx

我已经使用 flask-restx 实现了一个带有 swagger-ui 的 flask rest 服务器。 在没有 nginx 的情况下使用命令运行服务器时,我可以让 swagger-ui 工作

flask run --host=0.0.0.0

要么

uwsgi --ini app.ini

我的app.ini

[uwsgi]
module = wsgi:app

master = true
processes = 2

socket = /tmp/myproj.sock
chmod-socket = 666
vacuum = true

die-on-term = true

====================

但是,使用 nginx,尽管我的 REST API 可以正常工作,但我无法获得 swagger-UI。 我在浏览器上收到的错误消息:

在此处输入图像描述

/etc/nginx/sites-available/default中我的 nginx 配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    server_name _;

    location /api {     
        include uwsgi_params;
        uwsgi_pass unix:/tmp/myproj.sock;
    }
}

知道如何配置 nginx 以便可以加载 swagger-UI 吗? 谢谢你。

更新

我设法通过在 nginx 配置中添加 /swaggerui 使其工作。

示例代码:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ /index.html;
    }
  
  location /api {
    include uwsgi_params;
    uwsgi_pass unix:/tmp/myproj.sock;
  }

  location /swaggerui {
    include uwsgi_params;
    uwsgi_pass unix:/tmp/myproj.sock;
  }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM