Which webserver to use with Django? (updated for use in 2011)

20,430

1 - which one is the best for VPS, Apache or Nginx, using the latest release of course! please dont say: use lighty or cherokee...

Either will work fine.

2 - if for example the answer was: use ngnix, then, is it better to use one server or two, as in the past it was better to make two webservers?

The key point that is being made is that Django/Python should not serve your static resources. "Two servers" could be different physical servers, or instances, or virtual servers. Here's an example of configuring nginx to serve static files directly and then pass dynamic requests to Python:

From https://code.djangoproject.com/wiki/DjangoAndNginx:

server {
    listen 80;
    server_name localhost;
    location /site_media  {
        root /media/; # Notice this is the /media folder that we create above
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
        access_log   off;
        expires      30d; 
    }
    location / {
        # host and port to fastcgi server
        fastcgi_pass 127.0.0.1:8080;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
        }
}

3 - when i've checked my brain, i've found that there is only few free space aviable, so i dont want to learn something else, so do you think a 100% pythonic solution will be ok? CherryPy does it be a perfect solution, mean, CherryPy + Django and basta! no Apache, no Nginx, no more learning than python language!

IMO, setting up either Apache or nginx is pretty simple and there are lots of resources out there. You don't need to learn very much about them to setup something simple.

Share:
20,430

Related videos on Youtube

Abdelouahab
Author by

Abdelouahab

print "Hello world"

Updated on August 15, 2020

Comments

  • Abdelouahab
    Abdelouahab over 3 years

    I am asking this question because I am a beginner and I've read almost 90% of articles speaking about Django, but the problem is: Django was made and had problems for deploying, it is python, and python is not PHP! When reading Django tutorials, a beginner is in big problem, because he can find a tutorial "outdated" for example if you take a tutorial made in 2008 you'll see that they speak like the following:

    to deploy django, use apache, and dont forget to use another server for static files, for example nginx as a reverse proxy!

    But now, I found some articles saying that making a second server is useless because in the past, Django was served using mod_python which uses a lot of resources! So here is my question:

    1. Which one is the best for VPS, Apache or Nginx, using the latest release of course! Please dont say: use lighty or cherokee...
    2. If, for example, the answer was: use Ngnix, then, is it better to use one server or two, as in the past it was better to make two webservers?
    3. When I've checked my brain, I've found that there is only few free space avalaible, so I don't want to learn something else, so do you think a 100% pythonic solution will be ok? CherryPy does it be a perfect solution, mean, CherryPy + Django and basta! no Apache, no Nginx, no more learning than python language!
    4. From what I've read, Django and asynchronous servers are not "good friends", so does really get a good choise to use Nginx?

    Updated: added (4) about Django and asynchronous.

    • Marcin
      Marcin over 12 years
      I suggest you change the title to something like "django webserver configuration in 2011" - this will make it easier for others to search out.
    • Abdelouahab
      Abdelouahab over 12 years
      ok, i'll do it :) thanks for the suggestions :)
    • Abdelouahab
      Abdelouahab over 12 years
      *Updated: added (4) about django and asynchronous
    • cope360
      cope360 over 12 years
      @abdel, you should not add to your question after an answer has been accepted. I suggest you post that as a new question and specifically link to sources saying they are not "good friends."
    • Abdelouahab
      Abdelouahab over 12 years
      ok, thank you :) i did it, sorry am a beginner here :) stackoverflow.com/questions/7139976/nginx-on-windows-using-w‌​sgi
    • bdd
      bdd over 12 years
      hahah I love the "CherryPy + Django and <b> BASTA </b>!
  • Abdelouahab
    Abdelouahab over 12 years
    thank you :) sorry if i dident mention it, but am on windows, and do you think it's a good idea, nginx seems to have a bug, not more than 1024 requests/s !
  • agf
    agf over 12 years
    Do you really think you're going to be serving that many requests?
  • cope360
    cope360 over 12 years
    Do you have some dependency on Windows? Why not get a *nix VPS? It should be cheaper and python, web servers, etc. are better supported.
  • Abdelouahab
    Abdelouahab over 12 years
    agf sorry, but maybe i dont get the real problem: request means an active request or here they want to say idle users? cope360 i'm in algeria, and i dont think i can pay this offer from here, there is no credit card solution in algeria!
  • cope360
    cope360 over 12 years
    Request means from the time your server receives a GET, POST, etc. until it returns the response to the client. This process would normally take less than a second if your site is well designed. I think you may be confusing requests with sessions.
  • Abdelouahab
    Abdelouahab over 12 years
    so will the max 1024 problem will be only for requests? so the sessions will not have problems in windows?
  • cope360
    cope360 over 12 years
    If it says "max 1024 requests/s" then that will have no impact on how many sessions you can run. A website doing 1024/s would be a very highly trafficked site and you'd likely hit other bottlenecks first (like db latency).
  • Abdelouahab
    Abdelouahab over 12 years
    so i think nginx is my webserver, but the problem that when i've download a version, it came with a php config! :(
  • Abdelouahab
    Abdelouahab over 12 years
    am sorry, but can you please provide me some code that will be use in windows plateforme?