Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create https key and cert on localhost
cd ~/
mkdir .localhost-ssl
sudo openssl genrsa -out ~/.localhost-ssl/localhost.key 2048
sudo openssl req -new -x509 -key ~/.localhost-ssl/localhost.key -out ~/.localhost-ssl/localhost.crt -days 3650 -subj /CN=localhost
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/.localhost-ssl/localhost.crt
npm install -g http-server
echo "
function https-server() {
http-server --ssl --cert ~/.localhost-ssl/localhost.crt --key ~/.localhost-ssl/localhost.key
" >> ~/.bash_profile
source ~/.bash_profile
echo "You're ready to use https on localhost 💅"
echo "Navigate to a project directory and run:"
echo ""
echo "https-server"
Copy link

hashmil commented Jul 11, 2020


How can I put a folder in this https: server?
I can not locate the local host directory
Or where do I put my files to run the website/webapp

The local host directory is hidden. In terminal do a cd ~/ then do ls -a and you should see the folder created.
Also you dont need to put the folders anywhere. just cd to the folder and run https-server

Copy link

ollyde commented Oct 28, 2021

The script doesn't work. I get the following: /Users/junkbox/.bash_profile: line 9: `https-server': not a valid identifier

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