Skip to content

Commit

Permalink
problem: don't want to run my server as root to bind to privileged po…
Browse files Browse the repository at this point in the history
…rts (e.g. 80, 443).

solution: support privilege drop after socket bind via new --user <username> parameter.
  • Loading branch information
Niall O'Higgins committed Feb 27, 2012
1 parent 91bb2a9 commit 63ceb75
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/node-http-proxy
Expand Up @@ -16,6 +16,7 @@ var help = [
" --target HOST:PORT Location of the server the proxy will target",
" --config OUTFILE Location of the configuration file for the proxy server",
" --silent Silence the log output from the proxy server",
" --user USER User to drop privileges to once server socket is bound",
" -h, --help You're staring at it"
].join('\n');

Expand All @@ -24,8 +25,10 @@ if (argv.h || argv.help || Object.keys(argv).length === 2) {
}

var location, config = {},
port = argv.port || 80,
target = argv.target;
port = argv.port || 80,
target = argv.target
user = argv.user
;

//
// If we were passed a config, parse it
Expand Down Expand Up @@ -79,6 +82,14 @@ else {
//
server.listen(port);


//
// Drop privileges if requested
//
if (typeof user === 'string') {
process.setuid(user);
}

//
// Notify that the server is started
//
Expand Down

0 comments on commit 63ceb75

Please sign in to comment.