How to generate a self-signed SSL certificate with OpenSSL
A self-signed certificate is fine for local testing. Browsers will warn about it because no trusted authority signed it, so do not use it for a public website.
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365
req -x509creates a self-signed certificate instead of a request.-newkey rsa:2048creates a new 2048-bit RSA key.-nodesleaves the private key without a passphrase.-days 365sets the validity period.
OpenSSL asks for the name fields. Use the host name you will visit (for example localhost) as the Common Name.
Check the result
openssl x509 -in cert.pem -text -noout
For a real site
Use a certificate from a public authority. Many web servers, such as Caddy, can get free certificates automatically.