HTTPS locally without a commercial certificate.
Self-signed certificates are perfect for development and test environments. They allow working in HTTPS without having to buy a commercial certificate.
However, self-signed certificates should NEVER be used in production because browsers don't trust them.
This guide shows you how to create and use self-signed certificates effectively.
Understanding self-signed certificates:
Why use self-signed certificates:
Generation with OpenSSL:
Self-signed certificate generation:
# Generate key + certificate in one command (valid 365 days)
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout localhost.key -out localhost.crt \
-subj "/CN=localhost"
# With SAN for more flexibility
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout localhost.key -out localhost.crt \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,DNS:*.localhost,IP:127.0.0.1"
The -nodes flag avoids encrypting the private key with a password.
Tips for self-signed certificates:
No! Visitors will see scary warnings and most will leave your site.
The certificate isn't signed by a recognized certificate authority.
A tool that creates a local CA and installs it in your system to avoid warnings.
Yes, TLS encryption works exactly like with a commercial certificate.
You choose the duration with -days. For development, 365 days is convenient.
Add it to your OS's trusted certificate store or use mkcert.
Self-signed certificates are essential for developing in real HTTPS conditions without cost or complexity.
For production, use Let's Encrypt and monitor your certificates with MoniTao.
Start free, no credit card required.