如何在80端口上运行Node.js的? [英] How do I run Node.js on port 80?

查看:965
本文介绍了如何在80端口上运行Node.js的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在端口80这是因为我发现的Node.js正在从某些网络不容许任何其他端口的流量阻塞Node.js的运行。

My aim is to run Node.js on port 80. This is because I am finding node.js is being blocked from certain networks which do not allow traffic from any other port.

看来,要做到这一点的最好办法是通过Node.js的代理阿帕奇我一直在使用节点HTTP代理做这个尝试,但我没有任何运气。

It appears that the best way to do this is by proxying Apache through Node.js. I have tried using node-http-proxy to do this but I have not had any luck.

在code我使用的是在这里:

The code I am using is here:

var util = require('util'),
    http = require('http'),
    httpProxy = require('http-proxy');

httpProxy.createServer(9000, 'localhost').listen(80);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);

不过,我不断收到错误使用地址端口80。我必须做一些错误的。

But I keep getting the error "Address in use" for port 80. I must be doing something wrong.

如何使用节点HTTP代理做我的代理阿帕奇通过的node.js?这将使我在端口80上运行的node.js?而且是节点的HTTP代理实现这一目标的最佳途径?

How do I proxy Apache through node.js using node-http-proxy? Will this enable me to run node.js on port 80? And is node-http-proxy the best way to achieve this?

感谢您。

推荐答案

您需要做的是有2个IP对正在运行的服务器。阿帕奇有1个IP绑定到端口80,然后有node.js的绑定到端口80的其他知识产权。

What you need to do is have 2 ip's for the server you are running. Apache has 1 ip bound to port 80 and then node.js has the other ip bound to port 80.

使用节点和它听指令有2个值如。 。听(80 NODEJS_IP或DNS名称);

Using node and its listen directive has 2 values eg. .listen(80, NODEJS_IP or DNS NAME);

其他的一些建议。

因为它不是事件触发我不会用Apache支持的NodeJS。所以这真的是不推荐的。我真的考虑使用NGINX其与节点一个更好的配对。

I would not use apache with nodejs as it's not evented. So this really isn't recommended. I would actually look into using NGINX as its a much better pairing with Node.

这篇关于如何在80端口上运行Node.js的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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