This guide shows how to install and configure NGINX Docker with reverse proxy configurations and full grade A+ SSL Labs while also obtaining a LetsEncrypt cert via acme.sh client and CloudFlare DNS API.
To learn how to obtain CloudFlare DNS token check here or check acme.sh docs if you want to use a different method but you need to edit the script on your own.
# Variables {edit here}
export DOMAIN=
export ACME_EMAIL=
export CF_Zone_ID=""
export CF_Account_ID=""
export CF_Token=""
export PROXYADDRESS="http://proxy"
# End Variables {end edit}
# ACME.SH Installtion and Cert Issue {Paste in the terminal beginning from here}
cd /opt
git clone https://github.com/acmesh-official/acme.sh.git
cd ./acme.sh
./acme.sh --install -m ${ACME_EMAIL}
./acme.sh --upgrade --auto-upgrade
./acme.sh --set-default-ca --server letsencrypt
./acme.sh --issue --dns dns_cf -d ${DOMAIN} --keylength ec-384 --ocsp
# Docker Installtion and Configuration
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt update -y
apt install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
# NGINX Configurations
mkdir -p /opt/nginx/conf.d/${DOMAIN}
wget -O /opt/nginx/conf.d/${DOMAIN}.conf https://gist.githubusercontent.com/DonSYS91/be70f2a49776ab0eb1622a015cbcab51/raw/7256444dbfa86f6ea9fc9a416368adfa2ffd8d35/web.conf
sed -i "s/DOMAIN/$DOMAIN/" /opt/nginx/conf.d/${DOMAIN}.conf
sed -i "s|PROXY_ADDRESS|$PROXY_ADDRESS|" /opt/nginx/conf.d/${DOMAIN}.conf
# Docker NGINX + MariaDB Installation
docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 DockerBridge01
docker run -d --restart unless-stopped --name nginx-mainline --ip 172.18.0.2 --net DockerBridge01 -v /opt/nginx/conf.d/:/etc/nginx/conf.d/ -p 80:80 -p 443:443 nginx:mainline
# Install Cert and reload NGINX
./acme.sh --install-cert -d ${DOMAIN} --ecc --key-file /opt/nginx/conf.d/${DOMAIN}/web.key --fullchain-file /opt/nginx/conf.d/${DOMAIN}/web.crt --reloadcmd "docker exec nginx-mainline nginx -s reload"