Skip to content

Setup Local SSL

ucan-lab edited this page Feb 28, 2022 · 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

Edit: docker-compose.yml

services:
  web:
    ports:
      - 443:443

Edit: infra/docker/nginx/default.conf

server {
    # listen 80;
    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 ./*.pem /etc/nginx/conf.d/

Build docker image

$ docker compose build web

Destroy container

$ docker compose down

Create container

$ docker compose up -d

Access localhost

https://localhost

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

Clone this wiki locally