NGINX: Dynamische SSL-Konfiguration über Umgebungsvariable
- Aufteilung des NGINX-Templates in kbp_crm.nossl.conf.template (ohne SSL) und kbp_crm.ssl.conf.template (mit SSL) - Neues Skript 10-select-ssl.sh wählt Template zur Laufzeit basierend auf NGINX_USE_SSL (true/false) - Dockerfile: Vorbereitung für dynamische Template-Auswahl - docker-compose: Template-Verzeichnis auf /etc/nginx/configtemplates geändert, NGINX_USE_SSL als Umgebungsvariable hinzugefügt - .env: NGINX_USE_SSL=true standardmäßig aktiviert Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
1 parent
a6876fcc55
commit
ef563bad2f
7 files changed
+60
-3
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
# Parameter für NGINX-Server
|
# Parameter für NGINX-Server
|
||||||
NGINX_VERSION=mainline-alpine
|
NGINX_VERSION=mainline-alpine
|
||||||
|
NGINX_USE_SSL=true # true = SSL aktivieren, false = SSL deaktivieren, Port sollte auch angepasst werden
|
||||||
NGINX_HOST_PORT=443
|
NGINX_HOST_PORT=443
|
||||||
NGINX_SERVER_NAME=kbp_crm.mylocal.de
|
NGINX_SERVER_NAME=kbp_crm.mylocal.de
|
||||||
NGINX_STATIC_DIR=/home/schoschi/Entwicklung/Projekte_Runden/kbcrm/NGINX_Server/html
|
NGINX_STATIC_DIR=/home/schoschi/Entwicklung/Projekte_Runden/kbcrm/NGINX_Server/html
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Wählt das NGINX-Template abhängig von NGINX_USE_SSL aus.
|
||||||
|
# Kopiert das passende Template aus dem Staging-Mount (read-only) in das
|
||||||
|
# container-interne Verzeichnis, das vom envsubst-Skript verarbeitet wird.
|
||||||
|
# Läuft als 10-… vor dem eingebauten 20-envsubst-on-templates.sh.
|
||||||
|
|
||||||
|
src_dir="/etc/nginx/configtemplates"
|
||||||
|
dst_dir="/etc/nginx/templates"
|
||||||
|
|
||||||
|
# Falls noch ein Template aus einem vorherigen Start im dst_dir liegt, entfernen.
|
||||||
|
rm -f "$dst_dir"/kbp_crm.*.conf.template
|
||||||
|
|
||||||
|
if [ "$NGINX_USE_SSL" = "false" ]; then
|
||||||
|
cp "$src_dir/kbp_crm.nossl.conf.template" "$dst_dir/"
|
||||||
|
else
|
||||||
|
cp "$src_dir/kbp_crm.ssl.conf.template" "$dst_dir/"
|
||||||
|
fi
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
ARG NGINX_VERSION
|
ARG NGINX_VERSION
|
||||||
FROM nginx:${NGINX_VERSION}
|
FROM nginx:${NGINX_VERSION}
|
||||||
RUN ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
|
RUN ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
|
||||||
RUN mkdir /etc/certs
|
RUN mkdir -p /etc/certs /etc/nginx/templates
|
||||||
|
COPY 10-select-ssl.sh /docker-entrypoint.d/10-select-ssl.sh
|
||||||
|
RUN chmod +x /docker-entrypoint.d/10-select-ssl.sh
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Zunächst wird ein Default-Server definiert.
|
||||||
|
# Das Standardverhalten von NGINX ist nämlich wie folgt:
|
||||||
|
# Wenn im Request ein Server-Name reinkommt und NGINX keinen Server-Block findet, in dem dieser
|
||||||
|
# Servername definiert wird, wird einfach der erste definierte Serverblock genommen.
|
||||||
|
# Dadurch, dass ein expliziter Default-Server definiert wird, wird dieser verwendet.
|
||||||
|
# Falls jetzt also ein Servername übergeben wird, den es nicht gibt, gibt NGINX den Error-Code 404 zurück
|
||||||
|
server {
|
||||||
|
listen 4430 default_server;
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 4430;
|
||||||
|
server_name ${NGINX_SERVER_NAME};
|
||||||
|
resolver 127.0.0.11 valid=30s; # notwendig, damit der Upstream (s.u.) nicht direkt den nginx-Server stoppt, falls pythonapp noch nicht soweit ist
|
||||||
|
# https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/
|
||||||
|
|
||||||
|
location /static {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
# Variable muss benutzt werden (s.o. bei resolver Direktive)
|
||||||
|
set $upstream pythonapp:8080;
|
||||||
|
proxy_pass http://$upstream;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /health-check {
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
return 200 "success $time_iso8601";
|
||||||
|
}
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -10,9 +10,10 @@ services:
|
|||||||
- ${NGINX_HOST_PORT}:4430
|
- ${NGINX_HOST_PORT}:4430
|
||||||
volumes:
|
volumes:
|
||||||
- ${NGINX_STATIC_DIR}:/usr/share/nginx/html:ro
|
- ${NGINX_STATIC_DIR}:/usr/share/nginx/html:ro
|
||||||
- ${NGINX_CONFIG_TEMPLATE_DIR}:/etc/nginx/templates
|
- ${NGINX_CONFIG_TEMPLATE_DIR}:/etc/nginx/configtemplates:ro
|
||||||
- ${NGINX_CERTS}:/etc/certs
|
- ${NGINX_CERTS}:/etc/certs
|
||||||
environment:
|
environment:
|
||||||
|
- NGINX_USE_SSL=${NGINX_USE_SSL:-true}
|
||||||
- NGINX_CERT=${NGINX_CERT}
|
- NGINX_CERT=${NGINX_CERT}
|
||||||
- NGINX_CERT_KEY=${NGINX_CERT_KEY}
|
- NGINX_CERT_KEY=${NGINX_CERT_KEY}
|
||||||
- NGINX_SERVER_NAME=${NGINX_SERVER_NAME}
|
- NGINX_SERVER_NAME=${NGINX_SERVER_NAME}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ services:
|
|||||||
- ${NGINX_HOST_PORT}:4430
|
- ${NGINX_HOST_PORT}:4430
|
||||||
volumes:
|
volumes:
|
||||||
- ${NGINX_STATIC_DIR}:/usr/share/nginx/html:ro
|
- ${NGINX_STATIC_DIR}:/usr/share/nginx/html:ro
|
||||||
- ${NGINX_CONFIG_TEMPLATE_DIR}:/etc/nginx/templates
|
- ${NGINX_CONFIG_TEMPLATE_DIR}:/etc/nginx/configtemplates:ro
|
||||||
- ${NGINX_CERTS}:/etc/certs
|
- ${NGINX_CERTS}:/etc/certs
|
||||||
environment:
|
environment:
|
||||||
|
- NGINX_USE_SSL=${NGINX_USE_SSL:-true}
|
||||||
- NGINX_CERT=${NGINX_CERT}
|
- NGINX_CERT=${NGINX_CERT}
|
||||||
- NGINX_CERT_KEY=${NGINX_CERT_KEY}
|
- NGINX_CERT_KEY=${NGINX_CERT_KEY}
|
||||||
- NGINX_SERVER_NAME=${NGINX_SERVER_NAME}
|
- NGINX_SERVER_NAME=${NGINX_SERVER_NAME}
|
||||||
|
|||||||
Reference in new issue
Block a user