How To Set Up WordPress With Free SSL, Docker And nginx-proxy
Are you interested in setting up a new WordPress Instance with Docker, free SSL certificates with Lets Encrypt, and an automated reverse proxy with nginx-proxy? In this guide, I will give you simple step-by-step instructions to set up one or more WordPress Instances fulfilling these requirements.
Basics
You can use the setup from this guide for all your docker containers you want to host to the web and that you want to secure with free SSL certificates. It uses two containers that automate the whole setup for you!
VPS Hosting Course
Learn everything you need to know about servers and hosting your own applications!These containers are first the nginx-proxy that automatically creates new NGINX configurations for your new containers and second the letsencrypt-companion that automatically requests SSL certificates for it.
This was only a summary of how it works, for a more in-depth explanation check out my main post on this topic here. This post is mostly used as an example of how you can use it.
Docker Setup for free SSL, nginx-proxy, and WordPress
Let’s start immediately with creating the setup. Before you can use it you will need to install Docker and docker-compose on your machine (preferably some sort of linux server). Then you create a docker-compose.yml
file in the folder you want to work in. Insert the following content into the file:
services:
nginx:
container_name: nginx
image: nginxproxy/nginx-proxy
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /var/docker/nginx/html:/usr/share/nginx/html
- /var/docker/nginx/certs:/etc/nginx/certs
- /var/docker/nginx/vhost:/etc/nginx/vhost.d
logging:
options:
max-size: "10m"
max-file: "3"
letsencrypt-companion:
container_name: letsencrypt-companion
image: jrcs/letsencrypt-nginx-proxy-companion
restart: unless-stopped
volumes_from:
- nginx
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/docker/nginx/acme:/etc/acme.sh
environment:
DEFAULT_EMAIL: test@mail.com
Update the DEFAULT_EMAIL environment variable in the letsencrypt-companion container. With this, you created the basis for this setup. The automated reverse proxy and the automated SSL certificates. Now let’s add the WordPress configuration to the file!
Need help or want to share feedback? Join my discord community!
website:
image: wordpress
container_name: website
volumes:
- ./website:/var/www/html
environment:
WORDPRESS_DB_HOST: website-db:3306
WORDPRESS_DB_USER: website
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: website
VIRTUAL_HOST: website.com
LETSENCRYPT_HOST: website.com
depends_on:
- website-db
restart: unless-stopped
website-db:
image: mariadb
container_name: website-db
volumes:
- ./website-db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: website
MYSQL_USER: website
MYSQL_PASSWORD: password
restart: unless-stopped
Also in these two containers, you have to change the environment variables to your needs! After you added all this to the docker-compose.yml
file run docker-compose up -d
or docker compose up -d
to build the containers. After a while, you will be able to access your new WordPress instance under the VIRTUAL_HOST you set for the WordPress container (if you pointed this domain to your server already).
Conclusion
In this guide, we saw the free and automated SSL and NGINX setup from this post in action. With it, we created an SSL-secured WordPress instance in seconds.
If this guide is helpful to you and you like what I do, please support me with a coffee!
I hope this little guide was helpful for you and enabled you to set up your own WordPress instance!
In case you are interested in more content like this consider subscribing to my newsletter. I will use it to inform you about new content each month!
[convertkit form=2303042]