Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Last active November 15, 2021 11:34
Show Gist options
  • Save jonathantneal/e8c7278b22b0ab077cb051f63e9c8517 to your computer and use it in GitHub Desktop.
Save jonathantneal/e8c7278b22b0ab077cb051f63e9c8517 to your computer and use it in GitHub Desktop.
Setting up a local SSL (HTTPS) WordPress site

Setting up a local SSL (HTTPS) WordPress site

We’re going to walk through setting up HTTPS for a local WordPress site within vagrant. For this tutorial, we’ll pretend our domain is example.local and that our site lives in ~/vagrant-local/www/example. This entire process should only take a minute or two.


First, let’s use the openssl command to create a key and certificate for our site.

# generate the ssl key
# replace example with the real thing
openssl genrsa -out ~/vagrant-local/www/example/ssl.key 2048

# generate an signed ssl certificate
# replace example and example.local with the real thing
openssl req -new -x509 -key ~/vagrant-local/www/example/ssl.key -out ~/vagrant-local/www/example/ssl.crt -days 3650 -subj /CN=example.local

If we’re on a Mac, let’s use the security command to tell our computer to trust our certificate. We’ll run this command using sudo, so we might get asked for our password.

# replace example with the real thing
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/vagrant-local/www/example/ssl.crt

Next, let’s update our site config to use the key and certificate, too.

# replace example with the real thing
sed -i '' -e $'s/}/\\\n    ssl on;\\\n    ssl_certificate \\/srv\\/www\\/example\\/ssl.crt;\\\n    ssl_certificate_key \\/srv\\/www\\/example\\/ssl.key;\\\n}/' ~/vagrant-local/config/nginx-config/sites/example.conf

That’s it. Let’s activate the new configuration.

# replace example with the real thing
vagrant ssh -c "sudo cp /srv/config/nginx-config/sites/example.conf /etc/nginx/custom-sites/ && sudo service nginx restart"

Now we can visit our site over https.

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