nginxflaskswaggeruwsgiflask-restx

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


I have implemented a flask rest server with swagger-ui using flask-restx. I could get the swagger-ui working when running the server using command, without nginx

flask run --host=0.0.0.0

or

uwsgi --ini app.ini

My app.ini:

[uwsgi]
module = wsgi:app

master = true
processes = 2

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

die-on-term = true

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

However, with nginx, although my REST APIs are working, I couldn't get the swagger-UI. Error message I received on browser:

enter image description here

My nginx configuration in /etc/nginx/sites-available/default:

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

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

Any idea how to configure nginx so that swagger-UI could be loaded? Thank you.


Solution

  • Update

    I managed to make it works by adding /swaggerui in nginx configuration.

    Example code:

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