A simple way to run HTTPS on localhost

TL;DRIf you want to run https on localhost, you can use this handy dandy shell script.

curl -o && chmod +x && ./ dev_port=<your-port-here>

After being stumped on how to get https running for my django app – I ended up figuring out that stunnel is theĀ perfect solution for faking an ssl certificate on localhost (aka self-signed certs).

I’m pretty sure you could use this for any server that you are starting via the command line, so you could get local https / ssl for rails, sinatra, flask,, node or even PHP on your local machine.

First, install stunnel:

brew install stunnel # for mac

apt-get install stunnel # for debian/ubuntu

Now once it’s installed, let’s generate our necessary SSL keys and certificates:

cd ~/ &&
openssl genrsa 1024 > stunnel.key &&
openssl req -new -x509 -nodes -sha1 -days 365 -key ~/stunnel.key > ~/stunnel.cert &&
cat ~/stunnel.key ~/stunnel.cert > ~/stunnel.pem

Finally, let’s make a config file:


cert = /path/to/stunnel.pem
sslVersion = all
options = NO_SSLv2
foreground = yes
output = /path/to/stunnel.log # a path that exists

connect=3333 # or 8000 or whatever port you're running on

Now once that stunnel.conf is somewhere accessible, let’s start stunnel:

sudo stunnel stunnel.conf

And finally, we start the server šŸ™‚

python runserver 3333
rails s -p 3333
node app.js
php -S

Any voila. We have HTTPS running on localhost. Click here to confirm! If that’s too annoying, I made a little shell script to download & configure stunnel for port 8443 and forward to port 8000 that should work for Mac OS X (if you have homebrew installed), Ubuntu or Debian. This is what it looks like:



Ready to try UserPath for yourself?

Sign Up For Free!


Co-founder at UserPath. Often blogging about the stuff we're doing to make your apps better and users satisfied. Sometimes writing about experiments or research. Learner. Thinker. Programmer.