Skip to content

Instantly share code, notes, and snippets.

@katsube
Last active September 27, 2018 05:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katsube/d33cb3e1ee9db0bd7c873b44493d2e02 to your computer and use it in GitHub Desktop.
Save katsube/d33cb3e1ee9db0bd7c873b44493d2e02 to your computer and use it in GitHub Desktop.
Nodejs + expressで80番ポートを使用する(一般ユーザー)
/**
* 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