[Django]-How can I setup Nginx Proxy Buffering with Gunicorn over Amazon EC2?

4👍

You’re looking for the nginx HttpProxyModule I believe.
You define a upstream in nginx

upstream webservers {
    server 12.34.567.12:8000;
    server 21.43.765.21:8000;
}

And then forward requests via proxy_pass to the upstream.

server {
    listen 443; //Port you want nginx to listen on
    location / {
        proxy_set_header Host $http_host;
        proxy_read_timeout 330;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://webservers ;
     }
}

And unless I’m mistaken the HttpProxyModule buffers the entire request before passing it on.
This may break some items that require streaming or interaction during this process but that’s a limit you face.

My nginx is a bit rusty so it might not work but it should be something along these lines

👤EWit

1👍

You definitely want nginx sitting in front of gunicorn. It is a common setup and you can find a lot of resources to help you get started. I like this tutorial: http://senko.net/en/django-nginx-gunicorn/, which will also walk you through supervisord and setting up a virtualenv.

0👍

If your looking to host on EC2 with Ubuntu server than these are some good tutorials apart from the one mentioned by Nathan.

Best Of Luck with your deployment. If you find the answer helpful do accept the answer

Leave a comment