There are many scenarios where the Application is running in port 80 and we need to enable SSL on that. Each frameworks/languages provides a different ways to enable the HTTPS.
In this gist I created a small reverse-proxy server which handles the HTTPS connection and redirects to HTTP server internally
const fs = require('fs'); | |
const tls = require('tls'); | |
const net = require('net'); | |
const server = tls | |
.createServer( | |
{ | |
key: fs.readFileSync('/opt/ssl/certs/key.pem'), | |
cert: fs.readFileSync('/opt/ssl/certs/cert.pem'), | |
}, | |
clientToProxySocket => { | |
const proxyToServerSocket = net.createConnection( | |
{host: 'localhost', port: '80'}, | |
() => { | |
clientToProxySocket.pipe(proxyToServerSocket); | |
proxyToServerSocket.pipe(clientToProxySocket); | |
}, | |
); | |
}, | |
) | |
.listen(443); |
# start the original server in background | |
npm start & | |
# start the node-ssl-proxy | |
node ./node-ssl-proxy.js |
Top comments (0)