Skip to content

Instantly share code, notes, and snippets.

@rrichards
Forked from mehmetsefabalik/nginx-https-local.md
Created February 27, 2025 08:08
Show Gist options
  • Save rrichards/1fbdb4d33e5321f205cf3e11946ba2f1 to your computer and use it in GitHub Desktop.
Save rrichards/1fbdb4d33e5321f205cf3e11946ba2f1 to your computer and use it in GitHub Desktop.
Enable https on your local environment with nginx

enable https on your local environment

install mkcert and create certificates

brew install mkcert
mkcert -install
mkcert local.place-your-domain-here.com localhost 127.0.0.1 ::1

Two .pem files will be generated. rename them as domain.pem and domain-key.pem

add 127.0.0.1 local.place-your-domain-here.com to your /private/etc/hosts file

create nginx config file

touch nginx.conf

events {

}

http {
  server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate ~/domain.pem;
    ssl_certificate_key ~/domain-key.pem;
    server_name local.place-your-domain-here.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
  }
}

run nginx

nginx -c nginx.conf -p .

now you can open https://local.place-your-domain-here.com

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