我正在尝试从Flask-RESTplus获得Swagger UI,并在使用Nginx作为代理的服务器上工作。
Swagger在/ api上提供服务,并使用http://localhost:5000/api在本地工作。我正在尝试将Nginx设置为代理,以便可以转到http://ServerIP/api并查看Swagger UI。
我已经为Nginx尝试了许多配置,目前有
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5000;
proxy_redirect off;
proxy_intercept_errors on;
proxy_http_version 1.1;
}
但是,进入 http://ServerIP/api时,我只会看到空白页。在Chrome开发者工具中存在错误:
Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload (api:75)
指的是:
<script src="/swaggerui/swagger-ui-bundle.js"></script>
<script src="/swaggerui/swagger-ui-standalone-preset.js"></script>
<script type="text/javascript">
window.onload = function() {
const ui = window.ui = new SwaggerUIBundle({
但我能够到达(200行,提供了javascript文件)
http://ServerIP/swaggerui/swagger-ui-bundle.js http://ServerIP/swaggerui/swagger-ui-standalone-preset.js。
任何想法可能是什么问题?
请您参考如下方法:
类似的问题:Server response gets cut off half way through
发送大型上游文件时,Nginx需要具有写入临时文件夹的权限。通常您会在/var/log/nginx/error.log中看到它,例如
2018/06/28 16:34:48 [crit] ... open() "<tmp folder>/x/y/00000000z" failed (13:
Permission denied) while reading upstream, <request info...>
要解决此问题,您可以使用nginx:nginx(除非您已手动更改用户),例如
sudo chown -R nginx:nginx /var/lib/nginx。如果权限不小于7xx,则可能需要更改它,但这不应该成为问题。
或者,您可以设置
proxy_buffering off;,但是如果您希望连接比平时更长(速度或大小),则不建议这样做。

