Apache的节点JS里面 [英] Apache inside Node JS
问题描述
这个伟大的线程解释,如何使用的ProxyPass在Apache服务器拥有,该航线 /节点
转发到端口相匹配的一切:8080,其中有一个节点JS服务器运行:
This great thread explains, how to use ProxyPass in an Apache Server to have everything that matches the route /node
forwarded to port :8080, where there's a Node JS server running:
现在我不知道是否有一个类似的方式绕不这样做的其他方式。
Now I wonder whether there is a similar way do do this the other way around.
有两个正在运行的服务器的NodeJS:80:8080。但是,如果路由匹配 /博客
,它应该不是表明我的话preSS安装。
There are NodeJS servers running on both :80 and :8080. However, if the route matches /blog
, it should instead show my wordpress installation.
由于业务人建立我们的域名系统(哎呀),这是我能想到的唯一选择 - 子域名将无法正常工作
Due to a business guy setting up our domain system (argh), this is the only option I can think off - subdomains won't work.
推荐答案
您总是可以有做的NodeJS内部HTTP请求发送到正在运行的Apache服务(插座),基于你的HTTP的NodeJS听众传递的URL;然后只将结果返回通过相应的HTTP响应。
You can always have NodeJS make internal HTTP requests to your running Apache service (socket), based on the URL passed by your NodeJS http listener; then just feed the result back through the http response accordingly.
下面是关于如何使HTTP的NodeJS请求一个极好的职位: https://davidwalsh.name/nodejs
Here's an excellent post on how to make http requests with NodeJS: https://davidwalsh.name/nodejs-http-request
所以,如果你有即运行的Apache:IP&放大器;端口(插座) 127.0.0.1:4321
你可以有这样的Apache继电器的NodeJS请求:(只是一个例子)的
So, if you have Apache running on i.e: IP & port (socket) 127.0.0.1:4321
you can have NodeJS relay requests for Apache like this: (just an example)
var http = require('http');
http.createServer(function (nreq, nrsp)
{
if (nreq.url.indexOf('/blog') > -1)
{
http.get('http://127.0.0.1:4321', function(arsp)
{
arsp.on('data', function(data)
{
nrsp.write(data);
});
});
}
else
{
// your nodeJS web server stuff here
}
}).listen(8080); // or port 80, but this requires root privilege
这篇关于Apache的节点JS里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!