Each time I post asetup guide for configuring a Django serverthere are questions about how I came upon the Nginx and Apache multi-server approach as opposed to the myriad of alternatives. There are two parts to this question:
- Why a multi-server approach instead of a single-server approach?
- Why Nginx, Apache and
mod_python., fcgi, Lighttpd, etc?
This article will take a stab at explaining my reasoning for the first question: why use a multi-server setup to serve Django projects?
这种单一服务器方法的最大优点是简单性。特别是apache - 但其他系统也非常快速，非常无痛，可以为上面的配置设置（我找到nginx和fcgi一点直截了当，但肯定也是如此）。
That said, the single-server approach is a bit unwieldy when it comes to scaling your site for higher loads. As with other approaches, you can begin scaling the single-server setup vertically by purchasing a more powerful VPS or server, but trouble starts to sneak in when it is no longer cost-effective to increase capacity by upgrading your machine.
Although in reality you'd likely have Postgres on a separate machine.
In review, the single-server setup may be the most efficient option for low resource environments, is relatively simple to configure1, but must serve static and dynamic content with the same configuration, and thus may open itself up for inefficiencies as demands grow (we'll discuss this more below).
The Multi-Server Approach
mod_python.使用可能已阅读该术语脂肪螺纹, which is the word du jour for describing Apache worker threads when
mod_python.worker thread needs a Python interpreter associated with it, causing each worker thread to consume approximately 20 megs of ram.
There are good reasons for that, and
Essentially the argument being made be the multi-server setup is that specialization leads to efficiency. By allowing one server to focus only on serving dynamic media we can tweak its settings to maximize performance for that task. By allowing a second server to focus on serving static media, we can optimize it as well.
Beyond thespecialization leads to optimizationargument, the multi-server approach has another benefit over the single-server approach: ease of efficient scaling. Because we have separated the concerns from one another, it makes it very easy to scale efficiently by adding capacity exactly where it is needed.
With only minimal configuration file changes you could switch the simple one machine model to a many machine model. This is especially simple if the narrowest point in your pipe is serving dynamic content.
To a certain extent it's much easier to scale vertically (purchase a larger VPS or server) than to scale horizontally, and that should always be the first choice. However, should you reach a point where scaling vertically ceases to be cost-effective, the multi-server approach provides a tremendous amount of flexibility和allows higher gains per server due to specialization.
In the end, there isn't a right-wrong choice between using the single-server or the multi-server approach. While the multi-server approach willeventuallyout-perform the single-server approach, with limited resources may underperform it.
That said, my experience with the multi-server approach has been very positive, even with very limited resources (256 megabytes of RAM on a VPS), so--if you're willing to do some extra configuration--I'd personally recommend going with multi-server from the start.