Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Last active September 23, 2017 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-g/d3349e8bab99ab7b08fdccf92662a9aa to your computer and use it in GitHub Desktop.
Save jakub-g/d3349e8bab99ab7b08fdccf92662a9aa to your computer and use it in GitHub Desktop.
Generating self-signed SSL cert for node's http-server on Windows (Git Bash)

Quick tutorial how to serve current working directory over https, using self-signed cert, on Windows, from Git Bash, with NodeJS

npm install -g http-server

// follow this first if you use OpenSSL from Git Bash
https://gist.github.com/jakub-g/23699ec40cc23e5b8adfd8c9261487d6

// go to the folder that is to be served
cd /some/dir

// generate the cert. Keep pressing ENTER to use the defaults
openssl req -config /c/Program\ Files\ \(x86\)/Git/ssl/openssl.cnf -nodes -new -x509 -keyout key.pem -out cert.pem

// now optionally, gitignore the private and public cert files, so that they are not accidentally checked in to git
// I prefer to gitignore them globally
git config --global core.excludesfile ~/.gitignore_global
echo "key.pem" >> ~/.gitignore_global
echo "cert.pem" >> ~/.gitignore_global

// start the server with SSL enabled, on port 443
http-server --ssl -p 443
// or if you want to go fancy and have both http and https
http-server --ssl -p 443 & http-server -p 80 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment