我可以用Node.js的替代Apache的? [英] Can I Replace Apache with Node.js?

查看:217
本文介绍了我可以用Node.js的替代Apache的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用通常的嫌疑人(的Apache,MySQL和PHP)的CentOS运行一个网站。由于这个网站最初推出的时候,它已经演变颇有几分,现在我想要做的事情票友用它 - 即实时通知。从我读过,阿帕奇不好处理此。我想知道如果我可以用Node.js的(所以不是 LAMP 只替换它阿帕奇将LNMP)。

I have a website running on CentOS using the usual suspects (Apache, MySQL, and PHP). Since the time this website was originally launched, it has evolved quite a bit and now I'd like to do fancier things with it—namely real-time notifications. From what I've read, Apache handles this poorly. I'm wondering if I can replace just Apache with Node.js (so instead of "LAMP" it would "LNMP").

我试过的解决方案的在线搜索,但还没有找到一个。如果我是正确的跨preting我读过的事情,似乎大多数人都在说,Node.js的可以替代Apache和PHP在一起。我有很多现有的PHP code的,虽然如此,我倒是preFER保留它。

I've tried searching online for a solution, but haven't found one. If I'm correctly interpreting the things that I've read, it seems that most people are saying that Node.js can replace both Apache and PHP together. I have a lot of existing PHP code, though, so I'd prefer to keep it.

在情况下,它是不是已经很明显,我很困惑pretty并可以使用一些启示。非常感谢!

In case it's not already obvious, I'm pretty confused and could use some enlightenment. Thanks very much!

推荐答案

如果您是prepared重新写你的PHP在JavaScript中,那么,Node.js的可以取代你的Apache。

If you're prepared to re-write your PHP in JavaScript, then yes, node.js can replace your Apache.

如果您放在您的服务器和客户端之间的反向代理模式下运行的Apache或nginx的情况下,你可以处理的node.js的JavaScript中的一些请求,并在Apache,PHP托管一些请求,直到可以完全替代所有你的PHP的JavaScript code。这可能是折中:做你的WebSockets在Node.js的工作,阿帕奇+ PHP更平凡的工作。

If you place an Apache or nginx instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on node.js and some requests in your Apache-hosted PHP, until you can completely replace all your PHP with JavaScript code. This might be the happy medium: do your WebSockets work in node.js, more mundane work in Apache+PHP.

您可能总是需要一个Apache或Nginx的运行是一个无聊的Web服务器来处理服务所有静态文件:的sendfile(2)系统调用,使提供静态页面从真正的web服务器非常快(它消除了复制数据的双复制从磁盘进程的内存中,只有到内存复制到内核网卡 - 告诉内核您要发送哪些文件描述符的内容在该插座,内核可以安排直接从磁盘的数据复制到内核内存为网卡!活泉)。我不知道是否有node.js的容易获得的的sendfile(2)系统调用,但我会感到惊讶,所以我会假设运行的nginx处理静态文件将是值得拥有两个完整的服务器,同时加载到内存中。

You will probably always want an Apache or nginx running as a boring web server to handle serving all the static files: the sendfile(2) system call makes serving static pages from a real web server very fast (it removes the 'double-copy' of copying data into the process memory from disk, only to copy the memory into the kernel for the network card -- by telling the kernel which filedescriptor's contents you want sent over which socket, the kernel can arrange to copy data directly from disk to kernel memory for the network card! woot.) I don't know if node.js has easy access to the sendfile(2) syscall, but I would be surprised, so I would assume running an nginx to handle static files would be worth having two complete servers loaded into memory simultaneously.

这篇关于我可以用Node.js的替代Apache的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆