我在端口5000上本地运行了Flask(带有Flask-restplus)应用程序。当我在本地启动应用程序并转到URL以下时,我可以看到Swagger UI。
http://localhost:5000/api/#
但是,当我在NGINX,gunicorn后面运行它并转到
http://localhost:81/api/#
我得到以下错误
Can't read from server. It may not have the appropriate access-control-origin settings.
当我查看Chrome错误时,我看到有人向 http://localhost/api/swagger.json Colud发出请求,因为NGINX容器在端口81上运行,这就是问题吗?
$(function () {
window.swaggerUi = new SwaggerUi({
url: "http://localhost/api/swagger.json",
validatorUrl: "" || null,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
},
onFailure: function(data) {
log("Unable to Load SwaggerUI"); // <<<-- This is where it breaks
},
});
window.swaggerUi.load();
但是,我可以通过http://localhost:81/api/centres/1向我发送邮递员请求,并获得预期的数据
在过去三天的谷歌搜索后,选项是:
这就是我的服务器配置
server {
listen 81;
charset utf-8;
# Configure NGINX to reverse proxy HTTP requests to the upstream server
(Gunicorn (WSGI server))
location / {
# Define the location of the proxy server to send the request to
proxy_pass http://web:8000;
proxy_redirect http://localhost/api http://localhost:81/api;
# Redefine the header fields that NGINX sends to the upstream server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
}
它仍然没有显示我的招摇UI。我是这个Docker,Nginx和gunicorn世界的新手。如何解决这个问题?