<p>I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server. </p>

<p>I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow.</p>

<p>What i'm looking for is:</p>

<ul>
<li>Easy to set up</li>
<li>Fast and easy on resources</li>
<li>Can serve mediafiles</li>
<li>Able to serve multiple djangosites on same server</li>
<li>I would rather not install PHP or anything else that sucks resources, and for which I have no use for.</li>
</ul>

<p>I have heard of mod_wsgi and mod_python on Apache, nginx and lighty. Which are the pros and cons of these and have i missed someone?</p>

<p><strong>@Barry</strong>: Somehow i feel like Apache is to bloated for me. What about the alternatives?</p>

<p><strong>@BrianLy</strong>: Ok I'll check out mod_wsgi some more. But why do i need Apache if i serve static files with lighty? I have also managed to serve the django app itself with lighty. Is that bad in anyway? Sorry for beeing so stupid :-)</p>

<p><strong>UPDATE</strong>: What about lighty and nginx - which are the uses-cases when these are the perfect choice?</p>

[{'answer_id': 26057, 'author': 'Barry', 'author_id': 845, 'author_profile': 'https://Stackoverflow.com/users/845', 'pm_score': 3, 'selected': False, 'text': '<p>The officially recommended way to deploy a django project is to use mod_python with apache.  This is described in <a href="https://docs.djangoproject.com/en/1.2/howto/deployment/modpython/" rel="nofollow noreferrer">the documentation.</a>  The main pro with this is that it is the best documented, most supported, and most common way to deploy.  The con is that it probably isn\'t the fastest.</p>\n'}, {'answer_id': 26068, 'author': 'Brian Lyttle', 'author_id': 636, 'author_profile': 'https://Stackoverflow.com/users/636', 'pm_score': 3, 'selected': False, 'text': '<p>As @Barry said, the documentation uses <a href="http://modpython.org" rel="nofollow noreferrer">mod_python</a>. I haven\'t used Ubuntu as a server, but had a good experience with mod_wsgi on Solaris. You can find documentation for <a href="http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines" rel="nofollow noreferrer">mod_wsgi and Django</a> on the <a href="http://code.google.com/p/modwsgi/" rel="nofollow noreferrer">mod_wsgi</a> site.</p>\n\n<p>A quick review of your requirements:</p>\n\n<ul>\n<li><strong>Easy to setup</strong> I\'ve found apache 2.2 fairly easy to build and install.</li>\n<li><strong>Fast and easy on resources</strong> I would say that this depends on your usage and traffic. * You may not want to server all files using Apache and use <a href="http://www.lighttpd.net/" rel="nofollow noreferrer">LightTPD</a> (lighty) to server static files.</li>\n<li><strong>Can serve media files</strong> I assume you mean images, flash files? Apache can do this.</li>\n<li><strong>Multiple sites on same server</strong> Virtual server hosting on Apache.</li>\n<li><strong>Rather not install other extensions</strong> Comment out anything you don\'t want in the Apache config.</li>\n</ul>\n'}, {'answer_id': 26185, 'author': 'Jason Baker', 'author_id': 2147, 'author_profile': 'https://Stackoverflow.com/users/2147', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re using lighthttpd, you can also use FastCGI for serving Django.  I\'m not sure how the speed compares to mod_wsgi, but if memory serves correctly, you get a couple of the benefits that you would get with mod_wsgi that you wouldn\'t get with mod_python.  The main one being that you can give each application its own process (which is really helpful for keeping memory of different apps separated as well as for taking advantage of multi-core computers.</p>\n\n<p>Edit:  Just to add in regards to your update about nginix, if memory serves correctly again, nginix uses "greenlets" to handle concurrency.  This means that you may need to be a little bit more careful to make sure that one app doesn\'t eat up all the server\'s time.</p>\n'}, {'answer_id': 29748, 'author': 'jamting', 'author_id': 2639, 'author_profile': 'https://Stackoverflow.com/users/2639', 'pm_score': 6, 'selected': True, 'text': "<p>Since I was looking for some more in-depth answers, I decided to research the issue myself in depth. Please let me know if I've misunderstood anything.</p>\n\n<p>Some general recommendation are to use a separate webserver for handling media. By separate, I mean a webserver which is not running Django. This server can be for instance:</p>\n\n<ul>\n<li>Lighttpd (Lighty)</li>\n<li>Nginx (EngineX)</li>\n<li>Or some other light-weight server</li>\n</ul>\n\n<p>Then, for Django, you can go down different paths. You can either:</p>\n\n<ul>\n<li><p>Serve Django via <strong>Apache</strong> and:</p>\n\n<ul>\n<li><p><strong>mod_python</strong></p>\n\n<p>This is the stable and recommended/well documented way. Cons: uses a lot of memory.</p></li>\n<li><p><strong>mod_wsgi</strong></p>\n\n<p>From what I understand, mod_wsgi is a newer alternative. It appears to be faster and easier on resources.</p></li>\n<li><p><strong>mod_fastcgi</strong></p>\n\n<p>When using FastCGI you are delegating the serving of Django to another process. Since mod_python includes a python interpreter in every request it uses a lot of memory. This is a way to bypass that problem. Also there is some security concerns.</p>\n\n<p>What you do is that you start your Django FastCGI server in a separate process and then configures apache via rewrites to call this process when needed.</p></li>\n</ul></li>\n</ul>\n\n<p>Or you can:</p>\n\n<ul>\n<li><p>Serve Django <strong>without using Apache</strong> but with another server that supports FastCGI natively:</p>\n\n<p>(The documentation mentions that you can do this if you don't have any Apache specific needs. I guess the reason must be to save memory.)</p>\n\n<ul>\n<li><strong>Lighttpd</strong></li>\n</ul>\n\n<p>This is the server that runs Youtube. It seems fast and easy to use, however i've seen reports on memoryleaks.</p>\n\n<ul>\n<li><strong>nginx</strong></li>\n</ul>\n\n<p>I've seen benchmarks claiming that this server is even faster than lighttpd. It's mostly documented in Russian though.</p></li>\n</ul>\n\n<p>Another thing, due to limitations in Python your server should be running in forked mode, not threaded.</p>\n\n<p>So this is my current research, but I want more opinions and experiences.</p>\n"}, {'answer_id': 43800, 'author': 'Ryan Duffield', 'author_id': 2696, 'author_profile': 'https://Stackoverflow.com/users/2696', 'pm_score': 1, 'selected': False, 'text': '<p>We use nginx and FastCGI for all of our Django deployments.  This is mostly because we usually deploy over at Slicehost, and don\'t want to donate all of our memory to Apache.  I guess this would be our "use case".</p>\n\n<p>As for the remarks about the documentation being mostly in Russian -- I\'ve found most of the information on the <a href="http://wiki.codemongers.com/Main" rel="nofollow noreferrer">English wiki</a> to be very useful and accurate.  This site has sample configurations for Django too, from which you can tweak your own nginx configuration.</p>\n'}, {'answer_id': 108890, 'author': 'carefulweb', 'author_id': 12683, 'author_profile': 'https://Stackoverflow.com/users/12683', 'pm_score': 2, 'selected': False, 'text': '<p>The best configuration is not so known I think. But here is:</p>\n\n<ol>\n<li>Use nginx for serving requests (dynamic to app, static content directly).</li>\n<li>Use python web server for serving dynamic content.</li>\n</ol>\n\n<p>Two most speedy solutions for python-based web server is:</p>\n\n<ul>\n<li><a href="http://code.google.com/p/cogen/" rel="nofollow noreferrer">cogen</a></li>\n<li><a href="http://william-os4y.livejournal.com/4382.html" rel="nofollow noreferrer">fapws2</a></li>\n</ul>\n\n<p>You need to look into google to find current best configuration for django (still in development).</p>\n'}, {'answer_id': 126698, 'author': 'Roman Odaisky', 'author_id': 21055, 'author_profile': 'https://Stackoverflow.com/users/21055', 'pm_score': 2, 'selected': False, 'text': '<p>I’m using <strong>nginx</strong> (0.6.32 <a href="http://packages.debian.org/sid/nginx" rel="nofollow noreferrer">taken from Sid</a>) with <a href="http://wiki.codemongers.com/NginxNgxWSGIModule" rel="nofollow noreferrer"><strong>mod_wsgi</strong></a>. It works very well, though I can’t say whether it’s better than the alternatives because I never tried any. Nginx has <strong>memcached</strong> support built in, which can perhaps interoperate with the Django caching middleware (I don’t actually use it, instead I fill the cache manually using python-memcache and invalidate it when changes are made), so cache hits completely bypass Django (my development machine can serve about 3000 requests per second).</p>\n\n<p>A caveat: nginx’ <code>mod_wsgi</code> highly dislikes named locations (it tries to pass them in <code>SCRIPT_NAME</code>), so the obvious ‘<code>error_page 404 = @django</code>’ will cause numerous obscure errors. I had to patch mod_wsgi source to fix that.</p>\n'}, {'answer_id': 173517, 'author': 'akaihola', 'author_id': 15770, 'author_profile': 'https://Stackoverflow.com/users/15770', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m struggling to understand all the options as well. In <a href="http://www.technobabble.dk/2008/aug/25/django-mod-wsgi-perfect-match/" rel="nofollow noreferrer">this blog post</a> I found some benefits of mod_wsgi compared to mod_python explained.</p>\n\n<p>Multiple low-traffic sites on a small VPS make RAM consumption the primary concern, and mod_python seems like a bad option there. Using lighttpd and FastCGI, I\'ve managed to get the minimum memory usage of a simple Django site down to 58MiB virtual and 6.5MiB resident (after restarting and serving a single non-RAM-heavy request).</p>\n\n<p>I\'ve noticed that upgrading from Python 2.4 to 2.5 on Debian Etch increased the minimum memory footprint of the Python processes by a few percent. On the other hand, 2.5\'s better memory management might have a bigger opposite effect on long-running processes.</p>\n'}, {'answer_id': 353517, 'author': 'Oli', 'author_id': 12870, 'author_profile': 'https://Stackoverflow.com/users/12870', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m using <a href="http://www.cherokee-project.com/" rel="noreferrer">Cherokee</a>.</p>\n\n<p>According to <a href="http://www.cherokee-project.com/benchmarks.html" rel="noreferrer">their benchmarks</a> (grain of salt with them), it handles load better than both Lighttpd and nginx... But that\'s not why I use it.</p>\n\n<p>I use it because if you type <code>cherokee-admin</code>, it starts a new server that you can log into (with a one-time password) and configure the whole server through a beautifully-done webmin. That\'s a killer feature. It has already saved me a <em>lot</em> of time. And it\'s saving my server a lot of resources!</p>\n\n<p>As for django, I\'m running it as a threaded SCGI process. Works well. Cherokee can keep it running too. Again, very nice feature.</p>\n\n<p>The current Ubuntu repo version is very old so I\'d advise you use <a href="https://launchpad.net/~cherokee-webserver/+archive" rel="noreferrer">their PPA</a>. Good luck.</p>\n'}, {'answer_id': 994286, 'author': 'pbreitenbach', 'author_id': 42048, 'author_profile': 'https://Stackoverflow.com/users/42048', 'pm_score': 2, 'selected': False, 'text': '<p>Keep it simple: <a href="http://docs.djangoproject.com/en/dev/topics/install/" rel="nofollow noreferrer">Django recommends Apache and mod_wsgi (or mod_python)</a>. If serving media files is a very big part of your service, consider Amazon S3 or Rackspace CloudFiles.</p>\n'}, {'answer_id': 4039649, 'author': 'marcosluis2186', 'author_id': 413981, 'author_profile': 'https://Stackoverflow.com/users/413981', 'pm_score': 2, 'selected': False, 'text': '<p>There are many ways, approach to do this.For that reason, I recommend to read carefully the article related to the deployment process on DjangoAdvent.com:\nEric Florenzano - Deploying Django with FastCGI: <a href="http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/" rel="nofollow">http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/</a> \nRead too:\nMike Malone - Scaling Django\nStochastictechnologies Blog:  The perfect Django Setup\nMikkel Hoegh Blog: 35 % Response-time-improvement-switching-uwsgi-nginx</p>\n\n<p>Regards</p>\n'}, {'answer_id': 5942466, 'author': 'MechanisM', 'author_id': 438499, 'author_profile': 'https://Stackoverflow.com/users/438499', 'pm_score': 2, 'selected': False, 'text': "<p>In my opinion best/fastest stack is varnish-nginx-uwsgi-django.\nAnd I'm successfully using it.</p>\n"}, {'answer_id': 14844120, 'author': 'Alex Stewart', 'author_id': 1725981, 'author_profile': 'https://Stackoverflow.com/users/1725981', 'pm_score': 1, 'selected': False, 'text': '<p>I have a warning for using Cherokee. When you make changes to Django Cherokee maintains the OLD process, instead of killing it and starting a new one.</p>\n\n<p>On Apache i strongly recommend this article.</p>\n\n<p><a href="http://www.djangofoo.com/17/django-mod_wsgi-deploy-exampl" rel="nofollow">http://www.djangofoo.com/17/django-mod_wsgi-deploy-exampl</a></p>\n\n<p>Its easy to setup, easy to kill or reset after making changes.</p>\n\n<p>Just type in terminal</p>\n\n<pre><code>sudo /etc/init.d/apache2 restart\n</code></pre>\n\n<p>and changes are seen instantly.</p>\n'}]
['https://Stackoverflow.com/questions/26025', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2639/']