我一直在使用nginx作为gunicorn的反向代理;在docker容器内的生产环境中运行flask服务器。 我的问题是为什么我们在容器内使用nginx,因为gunicorn是http服务器本身。 我正在使用Istio在kubernetes中部署映像。因为我已经在使用Istio,所以应该删除Nginx吗?
我想从图片中删除nginx,因为很难同时配置nginx和gunicorn,它们都可以正常工作,但是在上传大数据(例如800MB json文件)时,nginx抛出504错误的网关。 我尝试将nginx和gunicorn配置为不超时,但不起作用.nginx通过查看pod /容器日志以504错误的网关响应后,gunicorn仍在处理数据,因此这意味着gunicorn不会仅nginx抛出此错误是。 这是配置。
Nginx http部分
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_connect_timeout 3600s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
proxy_redirect off;
proxy_pass http://app_server;
}
Gunicorn配置:
gunicorn --worker-tmp-dir /dev/shm/ --workers=2 --threads=4 --worker-class=gthread --limit-request-field_size 125000000 --limit-request-line 125000000 --timeout 3600 --keep-alive 3600 --bind unix:/tmp/gunicorn.sock run:app
答案 0 :(得分:0)
研究了这个主题后,我自己回答。 不建议在容器引用here中运行多个进程 因此,在容器内部不应使用nginx将请求重定向到实际的uwsgi服务器。我们可以直接与uwsgi一起使用,它将单个进程分叉给多个工作人员。