Let’s encrypt allows creation of free ssl certificate for your site. This will make the page safe and get a url such as https://topweb.se.
I start by creating a folder for which nginx.tmpl file should be located, which nginx uses to configure each site, via nginx reverse proxy. With a reverse proxy, nginx understands what it should show when going to a url. For example, in dns settings for a domain, we point to the server’s ipaddress. The server can have multiple websites and how does the server know which page to display? Well, with the help of a reverse proxy, the server understands it. Thus www.topweb.se shows a page and www.topwebtest.se shows another page, though they are on the same server and in different docker containers. Now, my root user is peter, do not forget to change to your correct root user or another user on your Ubuntu server.
sudo mkdir -pv /home/peter/docker/volumes/proxy/templates/
Go to the template folder and create a nginx.tmpl file
sudo nano nginx.tmpl
Then paste this code: nginx.tmpl
Create docker-compose file
Start by creating your own nginx docker network where all web sites will be located, so let’s encrypt detects when a new site is added and can create certificates.
docker network create nginx-proxy
Cd’a to the docker folder that was created earlier and create a docker-compose.yml file
sudo nano docker-compose.yml
Then paste this code for nginx with let’s encrypt: docker-compose.yml
Then we also have to open ports in the firewall.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Run docker-compose file
The last step is to run the nginx server and you run docker-compose.yml through the following command.
sudo docker-compose up
You can stay at that display and start a new ssh session with the server, if you are going to add a website, as we do in the next step of this tutorial. This is because in that display that comes, you can follow prints when creating the certificates etc.