Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Created June 29, 2016 19:41
Show Gist options
  • Save nemtsov/482c4f826ad3dd4b43a4dc3d267aaf23 to your computer and use it in GitHub Desktop.
Save nemtsov/482c4f826ad3dd4b43a4dc3d267aaf23 to your computer and use it in GitHub Desktop.
Simple HTTPS proxy server
var https = require('https');
var fs = require('fs');
var url = require('url');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var options = {
key: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_key.pem'),
cert: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_cert.pem'),
};
var server = https.createServer(options, function(req, res) {
var urlPath = url.parse(req.url).path;
https.get(process.env.PROXY_TO + urlPath, function(gres) {
res.setHeader('Content-Type', gres.headers['content-type']);
res.statusCode = gres.statusCode;
gres.pipe(res);
});
});
server.listen(3000, function() {
console.log('on :3000');
});
@nemtsov
Copy link
Author

nemtsov commented Jun 29, 2016

Note: generate your certs with:

openssl genrsa 1024 > ~/.ssh/self_signed_key.pem
openssl req -x509 -new -key ~/.ssh/self_signed_key.pem > ~/.ssh/self_signed_cert.pem

Set the COMMON NAME to your domain name. Don't add the protocol or port.


Start the server with:

env PROXY_TO=https://my.amazing.server.lan node proxy_server.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment