森栏
在绑定到端口80(或443)后删除根权限。这允许端口80/443保持保护,同时仍然阻止您以root用户身份服务请求:function drop_root() {
process.setgid('nobody');
process.setuid('nobody');}使用上述功能的完整示例:var process = require('process');var http = require('http');var server = http.createServer(function(req, res) {
res.write("Success!");
res.end();});server.listen(80, null, null, function() {
console.log('User ID:',process.getuid()+', Group ID:',process.getgid());
drop_root();
console.log('User ID:',process.getuid()+', Group ID:',process.getgid());});