Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django and nginx. Do I still need apache?

I've searched around on this topic, and the advice seems to be that nginx should be there to serve static files and apache+wsgi for dealing with Django. A lot of this information is a couple of years old, so I was wondering if there was a way to simplify this without performance degradation and just rely on Nginx and fastCGI and/or wsgi.

I'm new to non-heroku deployment, so this is why I probably sound like I don't know what I'm talking about.

like image 804
Scott Avatar asked Feb 19 '23 10:02

Scott


2 Answers

No you don't need Apache+wsgi along with Nginx+fCGI/wsgi. Nginx can serve static files really fast and it will use fCGI/wsgi for rest of the requests.

You should read answer to this questions[1] and other related questions mentioned there.

[1]. What is the disadvantage of using Django's fastcgi server

like image 179
pankaj28843 Avatar answered Feb 27 '23 13:02

pankaj28843


If you want to go the nginx route, the best choices are:

  • nginx -> gunicorn
  • nginx -> uWSGI

Running Python WSGI applications on top of FASTCGI is not generally as good an experience due to issues with the FASTCGI/WSGI adapters and how they are deployed with servers.

Apache/mod_wsgi is still a more than acceptable solution and it will actually perform better with less resources when run as:

  • nginx -> Apache/mod_wsgi

Because the bottlenecks aren't going to be the web server, ultimately it doesn't matter which you choose, so long as you set it up properly, something which most people wouldn't do as there site doesn't get enough traffic anyway, or they have no monitoring in place to know what they need to change.

Overall, picking which you think is easier to manage is the best thing to do when starting out.

For some background on what your real performance bottlenecks are going to be and the importance of monitoring, watch:

  • http://lanyrd.com/2012/pycon/spcdg/

That all said, you mention Heroku. Right now there is really only the once choice with Heroku and that is to use gunicorn and you wouldn't need to be worrying about nginx. That is a problem in itself though, as gunicorn alone is not a good option for serving static media assets so almost forced with Heroku to serve static assests elsewhere.

like image 36
Graham Dumpleton Avatar answered Feb 27 '23 14:02

Graham Dumpleton