Skip to content

Instantly share code, notes, and snippets.

@tanftw
Created November 19, 2024 04:36
Show Gist options
  • Save tanftw/3f228e1263cee338ddef5e95e1815d65 to your computer and use it in GitHub Desktop.
Save tanftw/3f228e1263cee338ddef5e95e1815d65 to your computer and use it in GitHub Desktop.
Self Signed Certificate

Generate

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/localhost.key -out /etc/ssl/certs/localhost.crt -config localhost.cnf

Config File (localhost.cnf)

[ req ]
default_bits        = 2048
default_md          = sha256
prompt              = no
distinguished_name  = dn
x509_extensions     = v3_req

[ dn ]
CN                  = localhost

[ v3_req ]
subjectAltName      = @alt_names

[ alt_names ]
DNS.1               = localhost

Nginx

server {
        listen 80;
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name localhost;
        ssl_certificate /etc/ssl/certs/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;

        ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

        #root /var/www/gif84;
        root /var/www/wp;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name localhost;
        client_max_body_size 256M;
        location / {
           try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

Install

Open the Certificate Manager:

Press Win + R, type mmc.exe, and press Enter.

Go to File > Add/Remove Snap-in.

Select Certificates and click Add.

Choose Computer account and click Next.

Select Local computer and click Finish.

Click OK to close the Add/Remove Snap-in window.

Import the Certificate:

In the Certificate Manager, expand Certificates (Local Computer).

Navigate to Trusted Root Certification Authorities > Certificates.

Right-click on Certificates, select All Tasks > Import.

Follow the Certificate Import Wizard to import your localhost.crt file.

Restart Your Browser:

After importing the certificate, restart your browser

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