我正在使用nginx代理后面的gunicorn运行一个烧瓶应用程序,并试图让gaiohttp工作者工作 . 当选择gaiohttp worker时,应用程序只返回所有URL的404
使用sync或gevent worker时一切正常 . 也没有直接运行gunicorn和gaiohttp即不使用nginx它工作正常 .
我已经阅读了我能找到的一切 .
我错过了什么吗?在nginx代理后运行时,gaiohttp worker是否有效?
我的nginx配置:
location /app {
proxy_pass http://127.0.0.1:9002;
rewrite /app(.*) /$1 break;
proxy_redirect off;
proxy_buffering on;
proxy_pass_header Server;
proxy_set_header X-Scheme $scheme;
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-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Script-Name /app;
}
gunicorn:
/usr/bin/gunicorn --workers 2 -k gaiohttp -b 127.0.0.1:9002 app:app
使用最新版本的gunicorn等
1 回答
我设法解决了这个问题 .
这里的行导致了nginx配置中的问题:
rewrite /app(.*) /$1 break;
我需要在我的Flask应用程序中使用代理中间件来正确处理反向代理 .
在应用程序的
__init__.py
中:app.wsgi_app = ReverseProxied(app.wsgi_app)