Docker × Laravel HTTPS (SSL) communication in local environment

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.

Laravel environment construction

$ git clone [email protected]:ucan-lab/docker-laravel.git
$ cd docker-laravel
$ make create-project

http://localhost

ScreenShot 2021-01-16 15.24.23.png

Certificate authority, key preparation

Installation of mkcert, nss

$ brew install mkcert nss

Creating a Local Certificate Authority (CA)

$ mkcert -install

Hide Chrome SSL warnings only on localhost. chrome: // flags/# allow-insecure-localhost Type in the address bar.

ScreenShot 2021-01-16 14.56.07.png

Change to DISABLED => ENABLED and restart your browser.

Creating private and public keys

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 code rewriting

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.

Docker image creation, container regeneration

Execute the command in the docker-laravel directory root.

$ docker-compose build web
$ make restart

https://localhost

ScreenShot 2021-01-16 14.54.27.png

ScreenShot 2021-01-16 14.54.39.png

It is ok if the SSL certificate is activated like this.

Recommended Posts

Docker × Laravel HTTPS (SSL) communication in local environment
SSL in the local environment of Docker / Rails / puma
Install laravel/Dusk in docker environment (laravel6)
ngrok --https communication in local environment (exposing the server to the outside)
Just install Laravel8 on docker in PHP8 environment
Rails5.1 + puma SSL connection in local production environment
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Build Couchbase local environment with Docker
Laravel + Docker Laradock usage environment construction
Build docker + laravel environment with laradock
Check MySQL logs in Docker environment
Alert slack with alert manager in Docker environment
[Docker] Use environment variables in Nginx conf
Launch Firebase Local Emulator Suite in Docker.
Use docker in proxy environment on ubuntu 20.04.1
Edit Mysql with commands in Docker environment
Run Redmine in the local environment of Windows10 Pro-Use Docker Desktop for Windows
Laravel + MySQL + phpMyadmin environment construction with Docker
Show Better Errors in Rails + Docker environment
How to migrate a web application created in a local docker environment to AWS
I had to lower the PHP version in Docker + Composer + Laravel environment
How to redirect to http-> https when SSL is enabled in Rails × Heroku environment
Solved DB connection and CORS problem when developing Laravel × Nuxt.js in Docker environment
Docker + DynamoDB local + C ++ environment construction and practice
Self-hosting with Docker of AuteMuteUs in Windows environment
(Basic authentication) environment variables in rails and Docker
[Rails] Run LINEBot in local environment using ngrok
Support out of support in docker environment using centos6
Wordpress local environment construction & development procedure with Docker
Docker + Laravel + Codeception
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
HTTP / HTTPS communication
Docker in LXD
Docker environment construction
Migration error after Activerecord association in Rails5 + Docker environment (2)
Points stuck when running vite + Nginx in Docker environment
Dramatically speed up slow bundle install in docker environment
Build WordPress environment with Docker (Local) and AWS (Production)
Make the strongest Laravel development environment (Docker) Japan time
Database environment construction with Docker in Spring boot (IntellJ)
I installed Squid on CentOS in my local environment