How to Enable HTTPS in Your Local Docker Environment
HTTPS is no longer optional — even in local development.
While we often skip setting it up during development, there are real benefits to running HTTPS locally.
Why bother with HTTPS in your local environment?
You’ll mirror your production setup more closely.
Some APIs (like OAuth or payment gateways) require HTTPS and simply won’t work over HTTP.
Certain browser features (like access to device’s microphone) only work over secure connections.
Let’s dive straight into setting it up.
Assumptions
You have custom domain setup in /etc/hosts
You current local environment is working fine with http
Create new folder under nginx folder named certs:
docker-compose.yml
nginx/
certs/
// your certificates will go here
Install mkcert on your computer
For Linux:
sudo apt install mkcert
For MacOs:
brew install mkcert
For Windows (Using Choco):
choco install mkcert
Create certificates
Make sure to replace “yourdomain” with your actual domain you have setup localy! 😄
Now open your terminal and go to certs/ directory you created.
Run:
mkcert -install
mkcert "*.yourdomain.test"
This will create 2 files:
_wildcard.yourdomain.test-key.pem
_wildcard.yourdomain.test.pem
Add mapping of certificates
Open docker-compose.yml file and add following lines:
Three dots (“…”) represent your existing settings, don’t add them. 😄
services:
nginx:
...
ports:
- ...
- "443:443"
volumes:
- ...
- ./nginx/certs:/etc/nginx/ssl
Add nginx configuration for domain
Open yourdomain.test.conf.
Mine is located :
nginx/
certs/
sites/
yourdomain.test.conf
You probably already have content in this file something like below:
server {
listen 80;
listen [::]:80;
...
}
You need to copy your config and paste it below and change ports and add certificates (so you have 2 server blocks one above the other):
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/ssl/_wildcard.yourdomain.test.pem;
ssl_certificate_key /etc/nginx/ssl/_wildcard.yourdomain.test-key.pem;
...
}
Rebuild nginx container and restart containers
docker compose build nginx
docker compose down && docker compose up -d

Cool post