Created
June 22, 2013 05:43
-
-
Save DanH42/5836006 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var fs = require('fs'); | |
var proxy = require('http-proxy'); | |
var crypto = require("crypto"); | |
var router = { | |
'domain1.com': "127.0.0.1:8001", | |
'domain2.com': "127.0.0.1:8002", | |
'domain3.com': "127.0.0.1:8003", | |
'domain4.com': "127.0.0.1:8004" | |
}; | |
var certs = { | |
"domain2.com": getCredentialsContext("domain2"), | |
"domain3.com": getCredentialsContext("domain3"), | |
"domain4.com": getCredentialsContext("snakeoil") | |
}; | |
var https_router = {}; | |
for(var i in certs) | |
https_router[i] = router[i]; | |
function getCredentialsContext(cer){ | |
if(cer === "snakeoil"){ // This is used as a global self-signed certificate | |
return crypto.createCredentials({ | |
key: fs.readFileSync("/etc/ssl/private/ssl-cert-snakeoil.key"), | |
cert: fs.readFileSync("/etc/ssl/certs/ssl-cert-snakeoil.pem") | |
}).context; | |
} | |
return crypto.createCredentials({ | |
key: fs.readFileSync("/etc/ssl/private/server.key"), | |
cert: fs.readFileSync("/etc/ssl/certs/" + cer + ".crt") | |
}).context; | |
} | |
var options = { | |
hostnameOnly: true, | |
enable: { | |
xforward: true | |
} | |
}; | |
var http_options = options; | |
http_options.router = router; | |
proxy.createServer(http_options).listen(80, "199.192.201.83"); | |
var https_options = options; | |
https_options.router = https_router; | |
https_options.https = { | |
SNICallback: function(hostname){ | |
return certs[hostname]; | |
}, | |
cert: fs.readFileSync('/etc/ssl/certs/ssl-cert-snakeoil.pem', 'utf8'), // As far as I can tell, this is served up when SNI fails (old browsers) | |
key: fs.readFileSync('/etc/ssl/private/ssl-cert-snakeoil.key', 'utf8'), | |
ca: [fs.readFileSync('/etc/apache2/ssl/ca.pem', 'utf8'), fs.readFileSync('/etc/apache2/ssl/sub.class1.server.ca.pem', 'utf8')] | |
} | |
proxy.createServer(https_options).listen(443, "199.192.201.83"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment