Skip to content

Instantly share code, notes, and snippets.

@EliEladElrom
Last active August 29, 2015 14:08
Show Gist options
  • Save EliEladElrom/7ac48008f5272632c6fc to your computer and use it in GitHub Desktop.
Save EliEladElrom/7ac48008f5272632c6fc to your computer and use it in GitHub Desktop.
Express, Node SSL certificate code snippets

create the SSL: https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server

clear ip tables


sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

set port to point


sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8000
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8081

curl http://54.187.197.239 -vvv --connect-timeout 2
curl https://54.187.197.239 -vvv --connect-timeout 2

Check the server:


var http  = require('http');
var https = require('https');

var options = {
        host: '54.187.197.239',
        port: 80
};

var protocol = http;
if (process.argv[2] && process.argv[2] === 'https') {
        protocol = https;
        options.port = 443;
}

var request = protocol.request(options, function(response) {
        // if we get a response we've connected
        response.destroy();
});

request.on('error', function(error) {
        var now = new Date();
        console.log(now.toISOString());
        console.log(error);
});

request.setTimeout(2000, function() {
        request.destroy();
        var now = new Date();
        console.log(now.toISOString());
        console.log('timeout');
});
@EliEladElrom
Copy link
Author


vim ~/.bashrc
# export

export PORT=8081
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8081
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8000

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