Skip to content

Instantly share code, notes, and snippets.

@Ryiski
Forked from mehmetsefabalik/nginx-https-local.md
Created January 14, 2024 16:55
Show Gist options
  • Save Ryiski/05a783a30925a73eda105e46bff65a4c to your computer and use it in GitHub Desktop.
Save Ryiski/05a783a30925a73eda105e46bff65a4c 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