Skip to content

Instantly share code, notes, and snippets.

@benatkin
Created April 24, 2011 08:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benatkin/939400 to your computer and use it in GitHub Desktop.
Save benatkin/939400 to your computer and use it in GitHub Desktop.
http/https server with node + express + ufw
// I edited this using the ACE editor bookmarklet
// http://ajaxorg.github.com/ace/build/textarea/editor.html
var express = require('express'),
fs = require('fs');
var app = express.createServer({
key: fs.readFileSync('positive.key'),
cert: fs.readFileSync('positive.pem'),
ca: fs.readFileSync('positive-chain.crt')
});
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(8081);
var redir = express.createServer();
redir.all('*', function(req, res){
res.redirect('https://rebl.us/');
});
redir.listen(8080);

I added this before *filter in /etc/ufw/before.rules. It redirects port 80 to 8080 and port 443 to 8081.

*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
COMMIT

*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8081
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment