我的机器上也运行着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 (末尾不带端口号)。
发布于 2016-06-14 00:16:47
Apache正在为您占用端口80。如果您尝试使用端口80启动您的节点服务器(假设您的apache已启动),您将得到一个权限错误。正确的方法是反向代理您的节点应用程序,并通过apache提供服务。您的apache配置应该如下所示。
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /path/to/your/node/app
Options -Indexes
ProxyRequests on
ProxyPass / http://localhost:2121/
</VirtualHost>另外,我给你的建议是,如果可能的话,使用Nginx,让生活变得更容易……
发布于 2016-06-13 23:52:00
默认情况下,http端口在80端口上运行,因此如果您这样做
`
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('hello');
}).listen(80);
console.log('Server running');`
您可以在http://localhost/上访问您的内容
还要记住,您不能在一个端口上运行多个应用程序。这是行不通的。
https://stackoverflow.com/questions/37792931
复制相似问题