views:

19909

answers:

12

A bit more context, in case this question is too general: the uses I have in mind are running django and serving static content and name-based virtual hosting.

I am vaguely aware of the performance/resource tradeoffs between the different servers, but that is a secondary concern.

Anyone who has deployed all three in production?

+2  A: 

Nginx and lighttpd are better for low-memory environments such as on a VPS. Apache is good if you want a wide range of configuration options. Since lighttpd is being "rewritten", I would go with nginx right now.

brian
+25  A: 

nginx get my vote by far. I've worked with all of the for years.

lighttpd is not an option right now, it's got major memory leak issues that have been outstanding for years, mark it off your list immediately.

the pros and cons of apache are well documented elsewhere, I'll let someone else address that.

nginx is very simple to configure, a dream for your static content task. I haven't run django behind nginx, but I've run 20 different servers with mongrels behind nginx, and it's really, really nice. Compared to apache, nginx is much less memory and cpu intensive, coupled with very simple config it's a simple decision in my book.

I would highly suggest you give it a shot before you sink the time into apache. It's possible that the python handling is better in apache, someone else can probably lend their experience.

ryan.scott
would you be able to provide a link to a summary of the apache pros and cons?
rz
+16  A: 

I run Django on Apache behind Nginx, with Nginx handling the static content. I'm happy with the arrangement, but if you really value simplicity of configuration over performance, you'd probably be happiest using just Apache alone. Can't beat the simplicity of configuring one webserver rather than two. (Running Django on just Nginx using FastCGI is possible, but IMO that's more difficult to configure and less well supported; you have to manually start the FCGI processes yourself).

If you use mod_wsgi in daemon mode and Apache's worker MPM, and you're careful not to bloat Apache with lots of unneeded modules, you still gain a lot of the same memory usage benefits as with a frontend Nginx: the Python code bloat is limited to only a few WSGI daemon processes and your Apache worker threads can stay quite slim for serving static content.

Carl Meyer
Running Django through FastCGI and nginx is quite easy.
Ryan Duffield
It still requires separate infrastructure to support your FastCGI processes and your webserver processes. If simplicity and ease of administration is the goal, I don't think it beats Apache/mod_wsgi.
Carl Meyer
+1 on answer and I completely agree with Carl's comment.
Van Gale
+1 This is the setup that I favour, and I've no complaints so far. Config is super easy.
Gary Chambers
I was wondering, is there a reason to run Apache and NGINX rather than just NGINX straight up?
resopollution
@resopollution see my comments about FastCGI etc. Apache+mod_wsgi is the officially-recommended, best-supported, and easiest method for hosting Django. That's why I don't run nginx alone.
Carl Meyer
adding a second web server to your stack just to get a FastCGI process spawned is ludicrous. see jefurii's comment below.
cce
A: 

Both lighttpd and nginx have similar memory footprint. Both serve well its purpose so it's a matter of personal taste - to me lighttpd configuration is easier to understand and maintain.

Apache has long been preferred solution but mod_python has some serious problems when it comes to more complicated configurations, for example running 2 Django apps with different LANGUAGE_CODE is impossible due to race condition in setting locale (you have to load separate interpreters or run separate apache instances, effectively making your apache to eat doubled amount of memory).

On the other hand, FastCGI processes are separated (and no, you do not need to start them separately, see runfcgi command of django-admin.py).

zgoda
+3  A: 

I pretty much agree with all that Carl Meyer writes. Wonder how Stack Overflow handles "me too" responses? :-)

The original question doesn't give much specific information about the intended use - expected load / requests per second, hosting type, etc. Assuming that the load is small'ish, I would recommend using just Apache with mod-wsgi, or Apache with mod-wsgi and S3 for static file serving.

mod-wsgi recently became the recommended way to deploy Django, see http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/ . Given this status, you should expect this method to see a lot of usage, and therefore a lot of documentation, tips'n'tricks and blog posts. Graham Dumpleton also recently release mod-wsgi 2.4 which looks quite mature (I haven't used it yet).

You can put nginx in front of Apache to proxy dynamic requests, and serve static files. This setup serves many people well. The nginx wiki has good tutorials on setting this up, http://wiki.nginx.org/Main . But this also gives you two sets of config files to learn, and two HTTP servers to keep updated.

Using only Apache, you could use Apache to serve static files, use mod-wsgi in deamon mode to handle Django. Then split up the requests by URL so that static file requests do not invoke the WSGI / Django stack, but are handled by Apache alone. This is again well documented, see your favorite Apache book for location handlers, or see the Apache / mod-wsgi docs. This at least 'centralizes' your learning, so that you only need to learn Apache & mod-wsgi configuration, and to keep Apache & mod-wsgi updated.

Another simple way to go would be to use Apache + mod-wsgi for all dynamic Django content, and put all static content on f.x. Amazon S3. Depending on your expected use / frequency of updating static content, this might be the very best. Amazon lists a couple of freeware applications to make working with S3 simple, such as S3Fox, Bucket Explorer etc.

HTH,

Jesper Mortensen
+9  A: 

I will not talk about apache... it is well known and documented. I'll talk about nginx vs lighttpd.

The second one (lighttpd) is much fore feature rich, easier to configure and it has a way better documentation. When talking about deployment of FCGI or SCGI application (the API Django actually use) there are several important point that lighttpd has:

  1. It provides support of spawning FCGI and SCGI application on its own, meaning it can fork and manage it for you if you want. (for scgi spawning use lighttpd >= 1.4.20). When it comes to nginx you must manage you fastcgi/scgi application on your own -- use your own startup scripts.
  2. It provides support of both TCP/IP sockets and Unix domain sockets for both protocols. (AFAIK nginx and apache does not provide support of unix domain sockets for SCGI).
  3. It provides native support of CGI PATH_INFO variable. In nginx you should do a silly workarounds using regular expressions to provide PATH_INFO that is not supported.
  4. nginx does not support CGI spawning, meaning that if you have a simple task to do that can be easily done with CGI, it is impossible for nginx to handle it.
  5. Configuration of FCGI for lighttpd a way simpler -- about 4-5 lines.

So... Nginx is indeed nice web server, but it isn't my first choice.

That is my little experience with FCGI/SCGI development using various servers.

Artyom
+1  A: 

I really like the way how nginx behaves under heavy load. I've experienced myself that its predictable memory footprint feature (due to asynchronous request handling) saves you a lot of pain.

The only problem with nginx I have is that you don't have per-directory configuration file (eg. .htaccess), which is usable when you host diffrerent applications each with its own rewrite requirements.

hegemon
+4  A: 

By far, lighttpd is the easiest to configure (as a matter of fact, I migrated from Apache to lighttpd due to configuration easiness/comfortableness).

Apache has far more options, and customizability, but, if you don't need that, stick with lighttpd. Most benchmarks out there give it about 50% better performance than Apache.

I've never used nginex, so I've no opinion on it in particular.

Hugo
+6  A: 

You might want to have a look at Cherokee, if ease of configuration and high performance are your goals. You'll find it friendlier than lighttpd as far as configuration, about if not more efficient than nginex and even hooks for some Apache compatibility (easy to port rewrites, etc).

I recently moved most of my lighttpd installations over to Cherokee with great success. I'm even using it as a front end load balancer, both for http and mysql. Its really a well written, very versatile and extremely friendly server.

Tim Post
Cherokee is very nice to configure (for single servers; more difficult to automate), but was very unstable last time I checked. I wouldn't recommend it at all, except for playing around. Wait for 1.0 and test it heavily then.
Lee B
While Cherokee 1.0 is out ( http://lists.octality.com/pipermail/cherokee/2010-May/012737.html ), my question about stability guarantees ( http://lists.octality.com/pipermail/cherokee/2010-May/012743.html ) brought about a response ( http://lists.octality.com/pipermail/cherokee/2010-May/012760.html ) that Alvaro has no intention of using anything other than a single development branch, which is a bit unnerving as a sysadmin.
Xiong Chiamiov
A: 

I'm running django on nginx+wsgi module (gentoo ebuild from connectical-contrib overlay), it's a speed of lightning compared to apache.

rr
But has unpredictable blocking behaviour in a multiprocess configuration, something which you would need to be careful of in a production environment. See 'http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.html'. Also, when you load up a fat Python web application and run with similar configuration, you wouldn't expect to seem much difference, as the underlying server isn't the bottleneck. Thus, you shouldn't rely on benchmarks from WSGI hello world applications as they are mostly meaningless.
Graham Dumpleton
+2  A: 

In reply to Carl Meyer's Jan 24 '09 answer,

(Running Django on just Nginx using FastCGI is possible, but IMO that's more difficult to configure and less well supported; you have to manually start the FCGI processes yourself).

There's a very handy init script on the Django site for managing multiple Django FCGI sites. You can start/stop/restart/status sites individually too.

jefurii
+1  A: 

One nginx feature I like a lot is the ability to reload its configuration on the fly without dropping any requests. lighttpd's solution for this (lighttpd-angel) will drop incoming requests on a busy system.

Comparing both nginx and lighttpd with Apache the biggest win I've found is the easy, per URL regex based configs which make complex configs with different settings for different directories (or file patterns) really easy to do.

Perry