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
This file contains 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
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); |
This file contains 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
# start the original server in background | |
npm start & | |
# start the node-ssl-proxy | |
node ./node-ssl-proxy.js |
Top comments (0)