为什么我们必须在容器中使用Nginx和Gunicorn进行烧瓶部署

问题描述

我一直在使用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

解决方法

研究了这个主题后,我自己回答。 不建议在容器引用here中运行多个进程 因此,在容器内部不应使用nginx将请求重定向到实际的uwsgi服务器。我们可以直接与uwsgi一起使用,它将单个进程分叉给多个工作人员。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...