Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active February 15, 2020 16:22
Show Gist options
  • Save Alex1990/e1c1025d5c0677f82b639659f42f8417 to your computer and use it in GitHub Desktop.
Save Alex1990/e1c1025d5c0677f82b639659f42f8417 to your computer and use it in GitHub Desktop.
Generate a self-signed ssl certificate
#!/usr/bin/env bash
# The "Common Name (CN)" can be "example.com" or "*.example.com www.example.com"
# This command should be executed in non-root mode
domain="$1"
if [ -z "$domain" ]; then
echo "need domain parameter"
exit 1
fi
san=$(cat <<-END
[SAN]
subjectAltName=@alt_names
[alt_names]
DNS.1=$domain
END
)
openssl req \
-newkey rsa:2048 \
-x509 \
-nodes \
-keyout "${domain}.key" \
-new \
-out "${domain}.crt" \
-reqexts SAN \
-extentions SAN \
-config <(cat /System/Library/OpenSSL/openssl.cnf \
<(echo "$san")) \
-sha256 \
-days 365
@Alex1990
Copy link
Author

  1. Configure the nginx
server {
  listen 443 ssl;
  server_name example.com;

  ssl_certificate /etc/ssl/private/example.com.crt;
  ssl_certificate_key /etc/ssl/private/example.com.key;
  ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
  ssl_protocols TLSv1.1 TLSv1.2;

  # ...
}
  1. Import the cert into "Keychain Access" and select "Always Trust"
  2. Open "Keychain Access" app.
  3. Select "System" in keychains.
  4. Select "Certificates" in Category.
  5. Click "Import Items" in File menu.
  6. Select the generated cert *.crt or *.pem.
  7. Right click on the imported certificate and Click "Get info"
  8. In the "Trust" section, select "Always Trust"
  9. Close the window.

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