Last active
September 27, 2018 05:30
-
-
Save katsube/d33cb3e1ee9db0bd7c873b44493d2e02 to your computer and use it in GitHub Desktop.
Nodejs + expressで80番ポートを使用する(一般ユーザー)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Nodejs + expressで80番ポートを使用する(一般ユーザー) | |
* | |
* Usage: | |
* $ sudo node index.js | |
* listening on *:80 | |
* | |
* 親プロセスはrootだが、子プロセスが指定したユーザーになるる。 | |
*/ | |
var app = require('express')(); | |
var http = require('http').Server(app); | |
app.get('/', function(req, res){ | |
res.send("<h1>It works.</h1>"); | |
}) | |
http.listen(80, function(){ | |
process.setuid(501); //ここのIDを変える | |
// $ id "ユーザー名" で表示される | |
console.log('listening on *:80'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment