This is simply a simplified version of the following tutorial.
Follow the wizard with a few exceptions. Parts that are important to change or important to leave as is are in bold:
- Choose to Override Details,
- Disable extended key usage
- Start Keychain Access.app.
- Select Keychain Access -> Certificate Assistant -> Create Certificate Authority
Name: Choose a friendly name for your CAIdentity type: select Self Signed Root CAUser certificate: Does not matter, we’ll delete it later. SSL Server for now.Let me Override Defaults: Check. Very important, you’ll see later why.Email from: Select email
Serial Number: Choose any number you like. I left it at 1.Validity Period (days): No longer than 825 daysCreate a CA web site: Unchecked.Sign your invitation: Uncheck
Press Continue
Email address: Up to youName (Common Name): Select something telling, such as "My Home CA"Organization,Unit,City,State,Country: Optional
Specify Key Pair Information For Users of This CA: 2048/RSA or longer
Press Continue
Include Key Usage Extensions: CheckedCapabilities:Signature: CheckedCertificate Signing: Checked
Press Continue
Extension is Critical: CheckedSSL Server Authentication: Checked
Leave the defaults
Include Subject ALternate Name Extension: CheckedThis extension is critical: Unchecked- Extension Values:
rfc822Name: EmptyURI: EmptyDNSName: Specify space-separated list of hostnames: localtestserver localtestserver.local localtestserver.example.comIPAddress: 127.0.0.1
Does not really matter. Complete the wizard.
Our certificate was created but it's not yet trusted. In order to trust it, follow these steps:
- open the Keychain Access > Certificates.
- Double click on your certificate
- Unfold
Trustand selectAlways Trusteverywhere.
Open Keychain Access again, search for newly created certificate. You will see three entries: Certificate, Public key and Private key.
- Select Certificate and export it to certificate.cer file.
- Select Private Key and export it to certificate.p12 file, with some pass-phrase.
openssl x509 -inform der -in certificate.cer -out server.crt
openssl pkcs12 -in certificate.p12 -out server.key -nodes
At the end of the file /etc/hosts, add your domain names listed in the certificate.
127.0.0.1 localtestserver.local
# Do the same for all domains listed in the certificate
Now you can use your certificates in nginx
server {
listen 443 ssl;
server_name localtestserver.local;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
ssl_certificate /path-to-my-certificate/server.crt;
ssl_certificate_key /path-to-my-certificate/server.key;
ssl_session_timeout 10m;
keepalive_timeout 70;
}