Skip to content

Instantly share code, notes, and snippets.

@Joris-van-der-Wel
Created August 13, 2014 22:14
Show Gist options
  • Save Joris-van-der-Wel/ec61c27ef9d299c0ea1f to your computer and use it in GitHub Desktop.
Save Joris-van-der-Wel/ec61c27ef9d299c0ea1f to your computer and use it in GitHub Desktop.
var fs = require('fs');
var http = require('http');
var httpProxy = require('http-proxy');
var pidfile = process.argv[2];
if (!pidfile)
{
console.log('Missing pidfile (first argument)');
process.exit(1);
}
var logfile = process.argv[3];
if (!logfile)
{
console.log('Missing pidfile (second argument)');
process.exit(1);
}
var logStream = fs.createWriteStream(logfile, {flags: 'a'});
process.__defineGetter__("stdout", function()
{
return logStream;
});
process.__defineGetter__("stderr", function()
{
return logStream;
});
require('daemon')();
console.log('*** Starting');
fs.writeFileSync(pidfile, process.pid);
process.on('exit', function() { try{fs.unlinkSync(pidfile);} catch(err){} });
process.on('SIGINT', function() { fs.unlinkSync(pidfile); process.exit(0); });
process.on('TERM', function() { fs.unlinkSync(pidfile); process.exit(0); });
var server = httpProxy.createServer({
https: {
key: fs.readFileSync('/var/node-https-proxy/somewebsite-key.pem', 'utf8'),
cert: fs.readFileSync('/var/node-https-proxy/somewebsite-cert.pem', 'utf8'),
ca: fs.readFileSync('/var/node-https-proxy/GandiStandardSSLCA.pem', 'utf8')
},
target : {
port : 80,
host : 'localhost'
},
enable : {
xforward: true // enables X-Forwarded-For
}
});
server.listen(443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment