From 08fb2a90997f6f8a26412bbfe4ff7f0503b11844 Mon Sep 17 00:00:00 2001 From: Trevor SANDY Date: Sat, 18 Jul 2026 16:45:39 +0200 Subject: [PATCH] Auto-configure refactor generate Caddyfile or nginx.template --- access/auto_config.sh | 240 +++++++++++++++++++++++++---------------- access/caddy/Caddyfile | 1 + 2 files changed, 149 insertions(+), 92 deletions(-) diff --git a/access/auto_config.sh b/access/auto_config.sh index f239c24..54cd669 100644 --- a/access/auto_config.sh +++ b/access/auto_config.sh @@ -1,6 +1,6 @@ #!/bin/bash # Trevor SANDY -# Last Update July 17, 2026 +# Last Update July 18, 2026 # Copyright (c) 2025-Present by Trevor SANDY # # Auto-configure, with user prompts, self-hosted AI-Suite with Caddy/Nginx proxy and @@ -2263,6 +2263,9 @@ write_dot_env_vars "${dot_env_vars[@]}" # NOTE: LLAMA and SearXNG are disabled in proxy config by default. # Set AC_LLAMA and AC_SEARXNG to anything other than empty, to enable: +append_caddy() { cat >>"$caddyfile_local"; } +append_nginx() { cat >>"$nginx_local_template_file"; } + # WRITE LOCAL Caddyfile if [[ "$proxy" == "caddy" ]]; then log_info "${HEADER}Write Caddyfile" @@ -2272,50 +2275,63 @@ if [[ "$proxy" == "caddy" ]]; then mkdir -p "$caddy_local_volume" # https://stackoverflow.com/a/3953712/18954618 - cat >"$caddyfile_local" <"$caddyfile_local" <<'EOF_CADDY' { # Global options - works for both environments - email {\$LETSENCRYPT_EMAIL} + email {$LETSENCRYPT_EMAIL} } import /etc/caddy/addons/cors.conf (configuration) { - $([[ "$CI" == true || "$AC_LOCAL" == true ]] && cat <<'TLS_INTERNAL' -tls internal -TLS_INTERNAL - ) +EOF_CADDY + + if [[ "$CI" == true || "$AC_LOCAL" == true ]]; then + append_caddy <<'EOF_TLS_INTERNAL' + tls internal +EOF_TLS_INTERNAL + fi + + append_caddy <<'EOF_CADDY' + +EOF_CADDY + + if [[ "$with_authelia" == true ]]; then + append_caddy <<'EOF_AUTHELIA_HANDLE' + @authelia path /authenticate /authenticate/* - $([[ "$with_authelia" == true ]] && cat <<'AUTHELIA_HANDLE' -@authelia path /authenticate /authenticate/* handle @authelia { reverse_proxy authelia:9091 } -AUTHELIA_HANDLE - ) +EOF_AUTHELIA_HANDLE + fi + + append_caddy <<'EOF_CADDY' handle { - $( +EOF_CADDY + if [[ "$with_authelia" == false ]]; then - cat <<'BASIC_AUTH' + append_caddy <<'EOF_BASIC_AUTH' basic_auth { {$PROXY_AUTH_USERNAME} {$PROXY_AUTH_PASSWORD} } -BASIC_AUTH +EOF_BASIC_AUTH else - cat <<'FORWARD_AUTH' - forward_auth authelia:9091 { + append_caddy <<'EOF_FORWARD_AUTH' + forward_auth authelia:9091 { uri /api/authz/forward-auth copy_headers Remote-User Remote-Groups Remote-Name Remote-Email } -FORWARD_AUTH +EOF_FORWARD_AUTH fi - ) + + append_caddy <<'EOF_CADDY' } } # N8N -{\$N8N_HOSTNAME} { +{$N8N_HOSTNAME} { import configuration # For domains, Caddy will automatically use Let's Encrypt # For localhost/port addresses, HTTPS won't be enabled @@ -2323,31 +2339,31 @@ FORWARD_AUTH } # OPENCLAW -{\$OPENCLAW_HOSTNAME} { +{$OPENCLAW_HOSTNAME} { import configuration reverse_proxy openclaw-gateway:18789 } # Open WebUI -{\$WEBUI_HOSTNAME} { +{$WEBUI_HOSTNAME} { import configuration reverse_proxy open-webui:8080 } # Flowise -{\$FLOWISE_HOSTNAME} { +{$FLOWISE_HOSTNAME} { import configuration reverse_proxy flowise:3001 } # Langfuse -{\$LANGFUSE_HOSTNAME} { +{$LANGFUSE_HOSTNAME} { import configuration reverse_proxy langfuse-web:3000 } # Supabase -{\$SUPABASE_HOSTNAME} { +{$SUPABASE_HOSTNAME} { import configuration @supa_api path /rest/v1/* /auth/v1/* /realtime/v1/* /functions/v1/* /mcp /api/mcp @@ -2365,37 +2381,47 @@ FORWARD_AUTH handle_path /goapi/* { reverse_proxy kong:8000 } +EOF_CADDY + + if [[ "$AC_LOGFLARE" == true ]]; then + append_caddy <<'EOF_LOGFLARE_HANDLE' - $([[ "$AC_LOGFLARE" == true ]] && cat <<'LOGFLARE_HANDLE' handle_path /logflare/* { reverse_proxy analytics:4000 } -LOGFLARE_HANDLE - ) +EOF_LOGFLARE_HANDLE + fi + + append_caddy <<'EOF_CADDY' handle { reverse_proxy studio:3000 } } +EOF_CADDY + +append_caddy <<'EOF_CADDY' # Neo4j -{\$NEO4J_HOSTNAME} { +{$NEO4J_HOSTNAME} { import configuration reverse_proxy neo4j:7474 } # SearXNG -$( -if [[ $AC_SEARXNG == true ]]; then - cat <<'SEARXNG_ENABLED' -{\$SEARXNG_HOSTNAME} { -SEARXNG_ENABLED -else - cat <<'SEARXNG_DISABLED' +EOF_CADDY + + if [[ "$AC_SEARXNG" == true ]]; then + append_caddy <<'EOF_SEARXNG_ENABLED' +{$SEARXNG_HOSTNAME} { +EOF_SEARXNG_ENABLED + else + append_caddy <<'EOF_SEARXNG_DISABLED' {DISABLED_SEARXNG} { -SEARXNG_DISABLED -fi -) +EOF_SEARXNG_DISABLED + fi + +append_caddy <<'EOF_CADDY' import configuration encode zstd gzip @@ -2453,29 +2479,28 @@ fi header_up Connection "close" } } -$( -if [[ $AC_LLAMA == true ]]; then - if [[ $AC_LLAMACPP == false ]]; then - cat <<'OLLAMA_BLOCK' +EOF_CADDY + + if [[ "$AC_LLAMA" == true ]]; then + if [[ "$AC_LLAMACPP" == false ]]; then + append_caddy <<'EOF_OLLAMA_API' + # Ollama API -{\$OLLAMA_HOSTNAME} { +{$OLLAMA_HOSTNAME} { reverse_proxy ollama:11434 } -OLLAMA_BLOCK - else - cat <<'LLAMACPP_BLOCK' +EOF_OLLAMA_API + else + append_caddy <<'EOF_LLAMACPP_API' + # LLaMA.cpp API -{\$LLAMACPP_HOSTNAME} { +{$LLAMACPP_HOSTNAME} { import configuration reverse_proxy llamacpp:8040 } -LLAMACPP_BLOCK +EOF_LLAMACPP_API + fi fi -fi -) -EOF - -# WRITE LOCAL nginx.template else log_info "${HEADER}Write Nginx Template" #------------------------------------------- @@ -2490,7 +2515,7 @@ else # https://github.com/JonasAlfredsson/docker-nginx-certbot/blob/master/docs/good_to_know.md#how-the-script-add-domain-names-to-certificate-requests cert_path="/etc/letsencrypt/live/automated-self-host" - cat >"$nginx_local_template_file" <"$nginx_local_template_file" <<'EOF_NGINX' upstream n8n_upstream { server n8n:5678; keepalive 2; @@ -2515,14 +2540,19 @@ upstream kong_upstream { server kong:8000; keepalive 2; } +EOF_NGINX + + if [[ "$AC_LOGFLARE" == true ]]; then + append_nginx <<'EOF_LOGFLARE_UPSTREAM' - $([[ "$AC_LOGFLARE" == true ]] && cat <<'LOGFLARE_UPSTREAM' upstream logflare_upstream { server analytics:4000; keepalive 2; } -LOGFLARE_UPSTREAM - ) +EOF_LOGFLARE_UPSTREAM + fi + + append_nginx <<'EOF_NGINX' upstream neo4j_upstream { server neo4j:7474; @@ -2533,32 +2563,39 @@ upstream langfuse_upstream { server langfuse-web:3000; keepalive 2; } +EOF_NGINX + + if [[ "$AC_SEARXNG" == true ]]; then + append_nginx <<'EOF_SEARXNG_UPSTREAM' - $([[ $AC_SEARXNG == true ]] && cat <<'SEARXNG_UPSTREAM' upstream searxng_upstream { server searxng:8081; keepalive 2; } -SEARXNG_UPSTREAM - ) +EOF_SEARXNG_UPSTREAM + fi + + if [[ "$AC_LLAMA" == true ]]; then + if [[ "$AC_LLAMACPP" == false ]]; then + append_nginx <<'EOF_OLLAMA_UPSTREAM' - $(if [[ $AC_LLAMA == true ]]; then - if [[ $AC_LLAMACPP == false ]]; then - cat <<'OLLAMA_UPSTREAM' upstream ollama_upstream { server ollama:11434; keepalive 2; } -OLLAMA_UPSTREAM +EOF_OLLAMA_UPSTREAM else - cat <<'LLAMACPP_UPSTREAM' + append_nginx <<'EOF_LLAMACPP_UPSTREAM' + upstream llamacpp_upstream { server llamacpp:8040; keepalive 2; } -LLAMACPP_UPSTREAM +EOF_LLAMACPP_UPSTREAM fi - fi) + fi + + append_nginx <