Skip to content

Recommended method to serve swagger ui behind nginx non-root location #611

Open
@billross00

Description

@billross00

I am trying to use flask and flask-restx to create multiple rest apis using nginx
In order to support multiple rest services I add locations to the nginx config
I am developing on a remote server, which is also my deployment server (one server for all rest apis)
Each rest api should have its own swagger doc
I am using a blueprint to alter the api.doc as shown in the restx documentation
I have started with just one simple rest api
I find that when serving with flask and gunicorn it works as expected, both the rest endpoint and the swagger doc work
But when I use nginx the endpoint works but the swagger doc is getting "the page you are looking for is not found"
I have been trying to resolve this over the last few days and have found many discussions on this issue dating back many years
All the way back to before flask-restful forked to flask-restx
I see many posted solutions, most involve using some combination of:
defining a custom_ui
changing the nginx location configuration for the reverse-proxy
adding additional nginx locations for swagger.json and swaggerui
I have tried many of these with no success
I see the github appears to have been updated with changes based on this issue.
I searched the restx documentation and could not find an example for my case.
Could someone either reply with the recommended solution or point me to an example for this case.
I have attached my simple restapi file as a text file
restapi.txt

key component versions

Flask==3.0.3
flask-restx==1.3.0
gunicorn==22.0.0
nginx version: nginx/1.14.1

nginx conf

location /restapi {
proxy_pass http://restapi/;
}
upstream restapi {
server unix:/run/gunicorn/restapi.sock;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions