同一服务器上的 Apache 和 Node.js [英] Apache and Node.js on the Same Server

查看:49
本文介绍了同一服务器上的 Apache 和 Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Node,因为它很快,使用与我在客户端使用的语言相同的语言,并且根据定义它是非阻塞的.但是我雇来编写文件处理程序(保存、编辑、重命名、下载、上传文件等)的那个人,他想使用 apache.所以,我必须:

I want to use Node because it's swift, uses the same language I am using on the client side, and it's non-blocking by definition. But the guy who I hired to write the program for file handling (saving, editing, renaming, downloading, uploading files, etc.), he wants to use apache. So, I must:

  1. 说服他使用 Node(他在这方面几乎没有放弃)

  1. Convince him to use Node (he's giving up little ground on that)

弄清楚如何在节点或

我必须在同一台服务器上安装 apache 和 node.

I must install apache and node on the same server.

哪种情况最有利,我该如何实施?

Which is the most favorable situation, and how do I implement that?

推荐答案

好问题!

有许多使用 PHP 实现的网站和免费网络应用程序在 Apache 上运行,很多人都使用它,因此您可以将一些非常简单的东西混搭在一起,此外,它是一种提供静态内容的简单方法.Node 是一种快速、强大、优雅且性感的工具,具有 V8 的原始功能和没有内置依赖项的扁平堆栈.

There are many websites and free web apps implemented in PHP that run on Apache, lots of people use it so you can mash up something pretty easy and besides, its a no-brainer way of serving static content. Node is fast, powerful, elegant, and a sexy tool with the raw power of V8 and a flat stack with no in-built dependencies.

我还想要 Apache 的易用性/灵活性以及 Node.JS 的笨拙和优雅,为什么我不能两者兼得?

I also want the ease/flexibility of Apache and yet the grunt and elegance of Node.JS, why can't I have both?

幸运的是 Apache ProxyPass 指令>httpd.conf 将特定 URL 上的所有请求通过管道传输到 Node.JS 应用程序并不难.

Fortunately with the ProxyPass directive in the Apache httpd.conf its not too hard to pipe all requests on a particular URL to your Node.JS application.

ProxyPass /node http://localhost:8000

另外,请确保以下几行没有被注释掉,以便您获得正确的代理和子模块来重新路由 http 请求:

Also, make sure the following lines are NOT commented out so you get the right proxy and submodule to reroute http requests:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

然后在端口 8000 上运行您的 Node 应用程序!

Then run your Node app on port 8000!

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Apache!\n');
}).listen(8000, '127.0.0.1');

然后您可以使用 url 上的 /node/ 路径访问所有 Node.JS 逻辑,网站的其余部分可以留给 Apache 来托管您现有的 PHP 页面:

Then you can access all Node.JS logic using the /node/ path on your url, the rest of the website can be left to Apache to host your existing PHP pages:

现在唯一剩下的就是说服您的托管公司让您使用此配置运行!!!

Now the only thing left is convincing your hosting company let your run with this configuration!!!

这篇关于同一服务器上的 Apache 和 Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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