Simple and automatic HTTPS proxy with Greenlock, LetsEncrypt and node-http-proxy

Posted on: 2018-08-21

Thanks to greenlock and node-http-proxy, creating a https proxy whith Let's Encrypt has never been easier. Basically, we just have to mix the two :

var Greenlock = require('greenlock'); var httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer({}); var redir = require('redirect-https')(); // let's create ou greenlock server first var greenlock = Greenlock.create({ // check greenlock's doc for the entire code sample }); require('http').createServer(greenlock.middleware(redir)).listen(80); require('https').createServer(greenlock.tlsOptions, function (req, res) { // proxy request instead of serving content : return proxy.web(req, res, { target: 'https://another-server.com', }); }).listen(443);

šŸ˜‰