Generating nginx certs on first startup.

This commit is contained in:
Roland 2026-02-24 17:14:56 -07:00
parent 4823a63773
commit f375e4c955
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 38 additions and 7 deletions

View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Generate self-signed SSL certificates for nginx if they don't exist.
set -e
CERT_FILE="/etc/nginx/cert.crt"
KEY_FILE="/etc/nginx/cert.key"
if [[ -f "${CERT_FILE}" && -f "${KEY_FILE}" ]]; then
echo "Certificates already exist at ${CERT_FILE} and ${KEY_FILE}"
exit 0
fi
echo "Generating nginx certificates..."
openssl genrsa -out "${KEY_FILE}" 2048
openssl req -new -x509 -nodes -key "${KEY_FILE}" -out "${CERT_FILE}" -days 3650 \
-subj "/C=US/ST=State/L=City/O=Org/OU=WROLPi/CN=$(hostname).local"
chmod 640 "${KEY_FILE}" "${CERT_FILE}"
echo "Certificates generated successfully."