I prefer static sites as it's easier to host and secure over CMS and dynamic ones. This is a container that will be used in a pipeline that will be created everytime I run an update and push changes on my site - this is for production use and not for testing as this one uses acme.sh to generate certificates at run time - if you restart the container lots of times you will get throttled by the SSL providers.
- Clone the repository to your chosen directory or fork it to your own repo.
- Put your static website files into the
sites
directory in the formatdomain.tld
, scripts will grab the folder name and use that to request certificates. - Update
env
file with your configuration.
To build the container, run:
docker build --no-cache -t static-nginx .
Replace the variables with your email. For provider configuration, visit acme.sh documentation
You must have the env file to run this.
env file format is:
DOMAIN[x].Variable=Value
The variable is passed directly to the runtime, so if acme.sh needs a variable such as CF_API_KEY then you should configure DOMAIN[x].CF_API_KEY.
docker run -d -p 80:80 -p 443:443 -v acme_conf:/root/.acme.sh --name static-site-webserver static-nginx
version: "3.8"
services:
websites:
container_name: static-site-webserver
image: YOUR_IMAGE
volumes:
- acme_conf:/root/.acme.sh
env_file:
- env
ports:
- 80:80
- 443:443
volumes:
acme_conf:
The container will run through the entire configuration and certificate request before it starts, so it really depends on the amount of domains you have.
...
nginx-websites | Starting Nginx...
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: using the "epoll" event method
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: nginx/1.24.0
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: OS: Linux 5.15.0-101-generic
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: start worker processes
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: start worker process 5928
nginx-websites | 2024/03/19 16:38:01 [notice] 5927#5927: start worker process 5929
...
- Package updates and isntallation of acme.sh.
- Copying all directories from
sites
directory and scripts. entrypoint.sh
callsscripts/generate-nginx-configs.sh
which:- Generation of simple nginx configuration to listen on
domain.tld
andwww.domain.tld
.
- Generation of simple nginx configuration to listen on
- renewal hook creation to restart nginx on certificate renewal.
- start nginx
- Dry run before generation of certs.
- Support for subdomains
- Support for custom nginx default configuration