Skip to content

Instantly share code, notes, and snippets.

@karlstolley
Last active February 9, 2022 21:38
Show Gist options
  • Save karlstolley/e3f8712c4ec7ea77822fc37464f84581 to your computer and use it in GitHub Desktop.
Save karlstolley/e3f8712c4ec7ea77822fc37464f84581 to your computer and use it in GitHub Desktop.
Command to generate SSL certificates for HTTPS; use with `http-server`
# ~/.zshrc or whatever your startup file is (.profile, .bashrc, etc.):
# https-server alias
alias https-server="http-server -S -C ~/Certs/localhost.crt -K ~/Certs/localhost.key -p 8443"
## NOTE: You will need to install `http-server` via npm by running:
#
# $ npm install -g http-server
#
#

Command to Generate Certs

Be sure to cd into ~/Certs first:

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 -days 1825 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

See https://letsencrypt.org/docs/certificates-for-localhost/

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