我正在使用 node.js 创建一个 HTTP 服务器,它工作正常但是在任何 Node 应用程序第一次运行时,Windows 安全防火墙会中断我的应用程序。我希望这个安全警报不应该显示,我有检查了很多引用资料,但没有找到我的答案。
这是我的代码:
var http = require('http');
var PORT = process.env.PORT || 3000;
http.createServer(function (req, res) {
console.log('%d request received', process.pid);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello world!\n');
}).listen(PORT);
console.log('%d listening on %d', process.pid, PORT);
最佳答案
允许通过 Windows 防火墙访问该应用程序:
- Go to: "Control Panel > System Ecurity > Windows Firewall > Advanced Settings".
- Create new rule.
- Select "Port" and press "Next".
- Allow TCP and port your are attempting to expose (default 3000, you might want to expose 80), and press "Next".
- Select "Allow the connection" and press "Next".
- Check all: Domain, Private, Public and press "Next".
我还建议您更换:
var PORT = process.env.PORT || 3000;
与:
var PORT = 3000;
关于在 Node.js 中创建 HTTP 服务器时的 Windows 安全警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971846/