0

I have a dedicated VPS running ZPanel (a managed LAMP stack installation) on Ubuntu. This allows me to easily add domains and PHP websites to my server and have each of them sandboxed to different ftp logins + mysql users which is pretty awesome.

Today I started messing around with some NodeJS apps. I was really impressed with the speed of these apps so I thought I'd throw them on my server. I created a new hosting account within zpanel as per usual, then started the app within an SSH terminal. As expected, the NodeJS app runs smoothly and I can still update its code via a separate FTP login just like I can with my existing PHP sites - fantastic!

All good up to here, but now comes the tricky part: getting NodeJS and Apache running in parallel on the same server...

The problem is that my NodeJS app runs on port 8080 (user defined) and Apache runs on port 80 (by default)

e.g. http://domain.com/:8080 <-- having the port in the url is obviously pretty confusing for users.

What would be the best solution to have any new nodejs apps & PHP websites accessible from http://newdomain.com/ as well as any existing PHP websites accessible from http://domain1.com/ , http://domain2.com/ or http://domain3.com/ instead of using the port?

These are the options I have come up with so far:

  1. Creating a 'sites-available' file on Apache for each domain that runs a Node app (ZPanel doesn't create this file by default). I'm guessing this is the simplest option but I've read that proxying from apache to Node is a speed & performance bottleneck as Apache is spawning additional processes on each request and then Node is doing its processing too.

  2. Changing all Apache websites to run off port 8080 and making Node run on port 80 instead. Then running a proxy with Node (on port 80 - the default http port) which would redirect a client to the correct url + port depending on the domain they visit. (Is it possible to run a node app globally for all domains attached to a server?) This seems like the most time consuming option, but wouldn't performance be greatly improved and my current hosting architecture would remain running pretty well?

  3. Any other option that I haven't thought of?

Remember: I am running every website (Node or PHP) on a different domain. I haven't come across a solution as sophisticated as this yet so I thought it'd be quite an interesting question as I'm sure a few others would be interested in a workflow like this (especially with git integrated!)

Please ask if further explanation is needed with this question and I will make edits if necessary.

Thanks in advance.

4

2 回答 2

0

如果没有超级用户权限,您可能无法让节点在端口 80 上运行,并且为您的节点应用程序提供这种权力根本不是一个好主意。让 apache 或(也是我的首选)nginx 在 80 上监听并传递请求要安全得多。(nginx 对套接字也更友好,总有一天你会想要这些)。

现在在我的开发箱上,我已经为 apache 和 node 应用程序提供了 nginx 代理。因为你不能有太多的服务器,我说;)

于 2013-11-21T01:18:19.973 回答
0

绝对通过 Apache 代理您的节点服务器。Apache 不仅可以比 Node 更快地提供静态文件,而且它实际上并不是一个瓶颈——然而,相反的情况并非如此。(虽然Nginx 绝对是我的首选。)

用 Apache Benchmark 试试吧!

$ ab -c 1000 -n 5000 http://127.0.0.1/

我的个人号码是:

  • 静态 Nginx 文件每秒 22,281 个请求
  • 节点每秒 5,514 个请求
  • 通过 Nginx 的 Node 每秒 4,729 个请求

如果您正在寻找更高的东西,Haskell's Warp 的速度约为 12,000/秒。:)

于 2013-11-21T00:37:48.790 回答