![](/img/trans.png)
[英]How to host flask-restx swagger UI using nginx reverse proxy
[英]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.