Menu Close
How Can We Help?
You are here:
Print

WebDev HTTPS localhost Windows

How to use OpenSSL to generate localhost certificates on Windows.

Create a new file localhost.conf with the following content.
Save it on your OpenSSL\bin folder.

01
02
03
04
05
06
07
08
[dn]
CN=localhost
[req]
distinguished_name = dn
[EXT]
subjectAltName=DNS:localhost
keyUsage=digitalSignature
extendedKeyUsage=serverAuth

Open a DOS Command Window (Windows+R > cmd.exe) on your OpenSSL\bin folder.
Execute the following commands:

01
02
openssl req -x509 -days 3650 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj "/CN=localhost" -extensions EXT -config localhost.conf
openssl x509 -inform PEM -in localhost.crt > localhost.pem

Right-click localhost.crt .
Select Install Certificate.
Select Local Machine.
Select Place all certificates in the following store.
Browse.
Select Personal.

Use the PEM and KEY files to config your webserver, in my case nginx and VSCode Live Server.

Remember to use the URL as https://localhost instead of https://127.0.0.1 .

To configure nginx to use this certificate and response full HTTP/2 resquest:
Copy .PEM and .KEY files to edit your nginx\conf folder.
Edit nginx.conf.
Search for # HTTPS Server.
Edit following with this settings:

01
02
03
04
05
06
listen       443 ssl http2;
listen  [::]:443 ssl http2 ipv6only=on;
server_name  localhost;
 
ssl_certificate      localhost.pem;
ssl_certificate_key  localhost.key;

Comments are welcome.