There is a request for HTTPS communication even in the local environment, and I just recently had the opportunity to do it at work, so I would like to summarize it in Qiita as well.
$ git clone [email protected]:ucan-lab/docker-laravel.git
$ cd docker-laravel
$ make create-project
http://localhost
$ brew install mkcert nss
$ mkcert -install
Hide Chrome SSL warnings only on localhost.
chrome: // flags/# allow-insecure-localhost
Type in the address bar.
Change to DISABLED
=> ENABLED
and restart your browser.
Execute the command in the docker-laravel
directory root.
$ mkcert -cert-file ./infra/docker/nginx/localhost.pem -key-file ./infra/docker/nginx/localhost-key.pem localhost
docker-compose.yml
Change the public port from 80
to 443
.
For HTTPS, 443
is generally used as the well-known port number.
docker-compose.yml
services:
web:
ports:
- ${WEB_PORT:-443}:443
infra/docker/nginx/default.conf
Add the following code.
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;
# ...abridgement
}
infra/docker/nginx/Dockerfile
Add the following code.
infra/docker/nginx/Dockerfile
COPY ./*.pem /etc/nginx/conf.d/
--The private key and public key are copied.
Execute the command in the docker-laravel
directory root.
$ docker-compose build web
$ make restart
https://localhost
It is ok if the SSL certificate is activated like this.
Recommended Posts