PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] Why do we must use nginx with gunicorn for flask deployment inside container

 September 01, 2022     docker, gunicorn, nginx, nginx-config, nginx-reverse-proxy     No comments   

Issue

I've been using nginx as reverse proxy to gunicorn; that runs the flask server in production env inside docker container. My question is why do we use nginx inside the container as gunicorn is http server itself. I'm deploying the image in kubernetes with Istio. as I'm already using Istio so should I remove nginx?

I want to remove nginx from the picture because it's hard to configure both nginx and gunicorn, these both works perfectly but when uploading large data e.g 800MB json files nginx throws 504 bad gateway. I've tried to configure nginx and gunicorn to not timeout but it doesn't work.After nginx responds with 504 bad gateway by seeing pod/container logs gunicorn is still processing the data so it means gunicorn isn't throwing this error only nginx is. Here is the configuration.

Nginx http section

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 config:

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

Solution

After researching on this topic I am answering it myself. It's not recommended to run multiple processes inside container ref: here So inside container one should not use nginx to redirect request to actually uwsgi server. we can directly serve with uwsgi that fork single process to multiple workers.



Answered By - Shabab Qaisar
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing