Why do I need nginx when I have uWSGI

You don’t.

That’s the simple answer, anyway — you don’t need it. uWSGI is itself a capable server.

However, other servers like nginx have been around longer and are (probably, anyway) more secure, as well as having additional features not supported by uWSGI — for example, improved handling of static resources (via any combination of Expires or E-Tag headers, gzip compression, pre-compressed gzip, etc.) that can significantly reduce server and network load; additionally, a server like nginx in front of your Django application can implement caching of your dynamic content as well, further helping to reduce server load, and even helping to facilitate the use of a CDN (which normally don’t do well with dynamic content). You could even go further and have nginx on a completely separate server, reverse proxying requests for dynamic content to a load balanced cluster of application servers while handling the static content itself.

For example, my blog (while it is WordPress, it does have nginx in front of it) is tuned to cache posts for 24 hours, and to cache index pages for 5 minutes; while I don’t see enough traffic for that to really matter most of the time, it helps my tiny little VPS weather the occasional surge that might otherwise knock it down — such as the big surge of traffic when one of my articles got picked up by a Twitterer with many thousands of followers, many of whom re-tweeted it to their thousands of followers.

If I had been running a “bare” uWSGI server (and assuming it had been a Django site, rather than WordPress), it might have stood up to it just fine — or it might have crashed and burned, costing me in missed visitors. Having nginx in front of it to handle that load can really help.

All that being said, if you’re just running a little site that won’t see a lot of traffic, there’s no real need for nginx or anything else — just use uWSGI on its own if that’s what you want to do. On the other hand, if you’ll see a lot of traffic… well, you still might want uWSGI, but you should at least consider something in front of it to help with the load. Actually, you should really be load-testing different configurations with your finished site to determine what does work best for you under your expected load, and use whatever that ends up being.

Leave a Comment