Hosting with free HTTPS in 5 minutes0 min read devops · web · software · docker
Aim of this post is to create hosting for your web application (or blog or webpage or anything-what-hosting-is-for) with free SSL certificate, so your page can be accessed securely with HTTPS. Certificate creation and renewal is going to be fully automated and adding new website is as simple as adding another Docker container.
This solution uses Let’s Encrypt certificates and is based on Docker containers.
Most of the steps described here you can also find in evertramos/docker-compose-letsencrypt-nginx-proxy-companion GitHub repository and has been copied and slightly arranged for my needs.
What NOT to expect
This post is not describing how to set up LAMP/LLMP/WAMP nor how to properly set PHP, Java or any other language/technology for hosting. It also should not be treated as full guide to set production-ready, secured VPS server with hosting capabilities.
How does it work
This solution is a combination of few tools:
- Nginx - reverse proxy and TLS termination
- docker-gen - generate Nginx configuration based Docker information
- letsencrypt-nginx-proxy-companion - allows the creation/renewal of Let’s Encrypt certificates automatically
- Linux server where you can install Docker e.g.:
- Domain name set up and pointing to your server.
- Docker installed on server (see Docker installation guide).
- Docker compose installed on server (see Docker compose installation guide)
Ready, set, go!
Clone Git repository:
$ git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.git
Make a copy of .env.sample and rename it to .env:
$ cd docker-compose-letsencrypt-nginx-proxy-companion $ cp .env.sample .env
Edit .env and change lines:
IP=0.0.0.0- put your public IP address (you can find by running
NGINX_FILES_PATH=/path/to/your/nginx/data- path should point to some directory you have write access (e.g. /home/your-user/nginx)
Run your application in Docker.
In this example this is simple static webpage. I am using
httpd:alpinedocker image to host this blog generated by Hugo.
$ docker run -d -e VIRTUAL_HOST=your.domain.com \ -e LETSENCRYPT_HOST=your.domain.com \ -e LETSENCRYPT_EMAILfirstname.lastname@example.org \ --network=webproxy \ --name my_app \ -v /path/to/files/on/host:/usr/local/apache2/htdocs/ \ httpd:2.4
If you want to host something more sophisticated, replace
httpd:alpineDocker image (e.g.
openjdkfor Spring Boot application or
php:apachefor PHP application) and mount the resources as Docker volume accordingly.
Wait few minutes for your certificate to be generated and set up.
Now you should be able to visit your application under https://your.domain.com.