nginx/apache/php 与 nginx/php 对比
我目前有一台带有 nginx 的服务器,它反向代理到 apache(同一服务器)来处理 php 请求。我想知道我是否放弃 apache,这样如果我看到任何性能提升,我就会将 nginx/fastcgi 运行到 php。我假设我会这样做,因为 Apache 相当臃肿,但同时我不确定 fastcgi/php 有多可靠,尤其是在高流量情况下。
我的网站每月约有 200,000 名独立访问者,每月来自搜索引擎的页面抓取量约为 6,000,000 次。这个数字正在稳步增加,因此我正在考虑性能选项。
我的网站在代码方面进行了非常优化,没有任何缓存(也不希望这样),每个页面最多有 2 个 sql 查询,没有任何其他表的联接,索引也很完美。
大约一年后,我将重写所有内容以使用 ClearSilver 作为模板,然后可能使用 python 或 c++ 来获得极致性能。
我想我或多或少正在寻求任何熟悉 nginx/fastcgi 的人的建议,并且是否愿意提供一些基准。我的站点是一台配备 1 个四核 Xeon、8GB 内存、150GB velociraptor 驱动器的服务器。
I currently have one server with nginx that reverse_proxy to apache (same server) for processing php requests. I'm wondering if I drop apache so I'd run nginx/fastcgi to php if I'd see any sort of performance increases. I'm assuming I would since Apache's pretty bloated up, but at the same time I'm not sure how reliable fastcgi/php is especially in high traffic situations.
My sites gets around 200,000 unique visitors a month, with around 6,000,000 page crawls from the search engines monthly. This number is steadily increasing so I'm looking at perfomrance options.
My site is very optimized code wise and there isn't any caching (don't want that either), each page has a max of 2 sql queries without any joins on other tables, indexes are perfect as well.
In a year or so I'll be rewriting everything to use ClearSilver for the templates, and then probably use python or else c++ for extreme performance.
I suppose I'm more or less looking for any advice from anyone who is familiar with nginx/fastcgi and if willing to provide some benchmarks. My sites are one server with 1 quad core xeon, 8gb ram, 150gb velociraptor drive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
nginx 肯定会比 Apache 运行得更快。我无法讲述 fastcgi,因为我从未将它与 nginx 一起使用过,但这个解决方案似乎在多个服务器上更有意义(一个用于静态内容,一个用于 fastcgi/PHP)。
如果您确实以性能为目标 - 甚至考虑 C/C++ - 那么您应该尝试 G-WAN,这是一款提供(非常快的)C 脚本的一体化服务器。
G-WAN 不仅内存占用小得离谱 (120 KB),而且其扩展能力无与伦比。如果您从 PHP 迁移,您还有很多工作要做,但您可以从性能关键型任务开始,然后逐步迁移。
我们已经完成了跳跃,不能考虑回到 Apache!
nginx will definitely work faster than Apache. I can't tell about fastcgi since I never used it with nginx but this solution seems to make more sense on several servers (one for static contents and one for fastcgi/PHP).
If you are really targeting performance -and even consider C/C++- then you should give a try to G-WAN, an all-in-one server which provides (very fast) C scripts.
Not only G-WAN has a ridiculously small memory footprint (120 KB) but it scales like nothing else. There's work ahead of you if you migrate from PHP, but you can start with the performance-critical tasks and migrate progressively.
We have made the jump and cannot consider to go back to Apache!
下面是一张图表,显示了 nginx、apache 和 g-wan 各自的性能:
g-wan.com/imgs/gwan-lighttpd-nginx-cherokee.png
apache 似乎并不领先(这是一个 -Quad XEON @ 3GHz)。
Here is a chart showing the respective performances of nginx, apache and g-wan:
g-wan.com/imgs/gwan-lighttpd-nginx-cherokee.png
apache does not seem to lead the pack (and that's a -Quad XEON @ 3GHz).
这是 g-wan 与 nginx、varnish 等的独立基准 http://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/
g-wan 每秒处理更多请求CPU 时间少得多。
Here is an independent benchmark for g-wan vs nginx, varnish and others http://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/
g-wan handles much more requests per second with much less CPU time.
NGINX 是当今网络服务器的最佳选择。
建筑学。 Apache 使用流程驱动的方法并创建
每个请求的新线程。而 NGINX 使用事件驱动
一个线程中处理多个请求的架构。
全面支持 Microsoft Windows 和 Windows NGINX 也运行在多个
现代类 Unix 系统并支持 Windows,但其
Windows 上的性能不如 UNIX 平台上的稳定。
.htaccess 文件。 Nginx 不允许额外的配置。
传递 URI 来解释请求。
打开/关闭。Nginx 有第 3 方核心模块(不是动态的)
可加载)。NGINX 提供了 Web 服务器的所有核心功能,
不牺牲轻量化和高性能品质
这使它成功。
Nginx 不够灵活,无法支持动态模块和加载。
免受任何伤害和黑客攻击。 Apache 提供了以下配置提示
DDoS 攻击处理,以及 mod_evasive 模块
响应 HTTP DoS、DDoS 或暴力攻击。
何时选择 Apache 而不是 NGINX?
每个目录的基础。
.htaccess 配置。
何时选择 NGINX 而不是 Apache?
当两者一起使用时
用户可以在 Apache 前面使用 Nginx 作为服务器代理。
NGINX is the best choice as a webserver now a days.
architecture. Apache uses a process-driven approach and creates a
new thread for each request. Whereas NGINX uses an event-driven
architecture to handle multiple requests within one thread.
has full support for Microsoft Windows & NGINX also runs on several
modern Unix-like systems and has support for Windows, but its
performance on Windows is not as stable as that on UNIX platforms.
.htaccess files. Where Nginx doesn’t allow additional configuration.
Passes URI to interpret requests.
turned On/Off.Nginx have 3rd Party core modules (not dynamically
loadable).NGINX provides all of the core features of a web server,
without sacrificing the lightweight and high-performance qualities
that have made it successful.
Nginx is not flexible enough to support dynamic modules and loading.
safe from any harm and hackers. Apache offers configuration tips for
DDoS attack handling, as well as the mod_evasive module for
responding to HTTP DoS, DDoS, or brute force attacks.
When Choose Apache over NGINX?
a per-directory basis.
.htaccess configuration.
When Choose NGINX over Apache?
When Use Both of them -Together
User can use Nginx in front of Apache as a server proxy.