Enhance nginx container to automatically generate self-signed certificates in absence of existing certificate files.

This commit is contained in:
Eduardo Silva
2024-03-05 13:26:18 -03:00
parent 8bc32d035b
commit 3307a39eb1
5 changed files with 33 additions and 12 deletions

15
nginx_entrypoint.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Diretório onde os certificados devem ser armazenados
CERT_DIR="/certificate"
# Checa se ambos os arquivos de certificado existem
if [ ! -f "$CERT_DIR/nginx.key" ] || [ ! -f "$CERT_DIR/nginx.pem" ]; then
echo "Creating self signed certificate..."
openssl req -x509 -newkey rsa:4096 -nodes -keyout "$CERT_DIR/nginx.key" -out "$CERT_DIR/nginx.pem" -days 3650 -subj "/CN=localhost"
else
echo "Skipping self signed certificate creation, files already exist."
fi
# Executa o comando original do Docker (CMD) passado para entrypoint.sh
exec "$@"