Skip to content

Setup Local SSL

ucan-lab edited this page Jul 7, 2023 · 9 revisions

Install mkcert, nss

$ brew install mkcert nss

mkcert: Create CA(Certification Authority)

$ mkcert -install

Chrome settings

https://camo.qiitausercontent.com/123834d9ee93f8b589210b532fa557045a3b0de3/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f35323837392f33393563363362362d326566382d353336322d373366652d6435613663663962633137612e706e67

  • chrome://flags/#allow-insecure-localhost
    • DISABLED => ENABLED

mkcert: Create private key and public key

$ mkcert -cert-file ./infra/docker/nginx/localhost.pem -key-file ./infra/docker/nginx/localhost-key.pem localhost

Add .gitignore file

$ echo '*.pem' >> ./infra/docker/nginx/.gitignore

Edit: compose.yml

services:
  web:
    ports:
      - target: 443
        published: 443
        protocol: tcp
        mode: host

Edit: infra/docker/nginx/default.conf

server {
    # listen 80;
    # listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name localhost;
    ssl_certificate /etc/nginx/conf.d/localhost.pem;
    ssl_certificate_key /etc/nginx/conf.d/localhost-key.pem;

    # ...
}

Reference: http://nginx.org/en/docs/http/configuring_https_servers.html

Edit: infra/docker/nginx/Dockerfile

COPY ./infra/docker/nginx/*.pem /etc/nginx/conf.d/

Build & Up

$ docker compose down
$ docker compose build web
$ docker compose up -d

Access localhost

https://localhost

https://camo.qiitausercontent.com/993ab32b8e48cac7e8797998c59c93a60dc1ea31/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f35323837392f37343832346533352d386130662d343437642d336465342d3266626630383537363561342e706e67