【发布时间】:2016-10-14 01:25:56
【问题描述】:
我的机器上也运行着 Apache,我必须在不添加端口号的情况下运行我的应用程序。
当我使用以下命令从http://localhost:2121 访问它时,它可以工作:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('hello');
}).listen(2121);
console.log('Server running');
如何将其设置为使用http://localhost(末尾没有端口号。)
【问题讨论】:
-
您只需执行
.listen(80)- 但是,如果 apache 已经在端口 80 上运行,它将无法工作,因为您不能让两台服务器在同一个端口上侦听。 -
可能是时候了解更多关于 Apache mod-proxy 插件以及如何将流量从 :80 重定向到 :2121
-
好问题好友@vikrant。
标签: javascript node.js server