From 75e154ecea998cfa274bc68e4f4bd5c98e342333 Mon Sep 17 00:00:00 2001 From: Yury Kossakovsky Date: Wed, 6 Aug 2025 18:57:40 -0600 Subject: [PATCH] Update Dify configuration in .env.example and Caddyfile - Removed deprecated DIFY_DB and DIFY_CELERY_BROKER_URL variables from .env.example. - Updated Caddyfile to change the reverse proxy port for Dify from 80 to 8080. - Enhanced start_services.py to dynamically set NGINX_PORT to prevent port conflicts. --- .env.example | 10 ---------- Caddyfile | 2 +- start_services.py | 24 ++++++++++++++++++++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 0df59f9..0082c93 100644 --- a/.env.example +++ b/.env.example @@ -295,16 +295,6 @@ LANGCHAIN_API_KEY= # Based on: https://docs.dify.ai/en/getting-started/install-self-hosted/environments ############ DIFY_SECRET_KEY= -# Dify uses shared Redis and PostgreSQL from n8n-installer -DIFY_CELERY_BROKER_URL=redis://redis:6379/1 -DIFY_DB_HOST=postgres -DIFY_DB_PORT=5432 -DIFY_DB_USERNAME=postgres -DIFY_DB_PASSWORD=${POSTGRES_PASSWORD} -DIFY_DB_DATABASE=dify -DIFY_REDIS_HOST=redis -DIFY_REDIS_PORT=6379 -DIFY_REDIS_DB=0 ########################################################################################### COMPOSE_PROFILES="n8n,flowise,monitoring" diff --git a/Caddyfile b/Caddyfile index 177d8fa..999e58f 100644 --- a/Caddyfile +++ b/Caddyfile @@ -22,7 +22,7 @@ # Dify {$DIFY_HOSTNAME} { - reverse_proxy dify-nginx:80 + reverse_proxy dify-nginx:8080 } # Langfuse diff --git a/start_services.py b/start_services.py index 977f596..b891a57 100755 --- a/start_services.py +++ b/start_services.py @@ -171,6 +171,7 @@ def prepare_dify_env(): # Get the secret key from main .env secret_key = env_values.get("DIFY_SECRET_KEY", "") + dify_nginx_port = env_values.get("DIFY_NGINX_PORT", "8080") if secret_key: # Replace SECRET_KEY if it exists, otherwise append it @@ -186,26 +187,45 @@ def prepare_dify_env(): # Append SECRET_KEY at the end dify_env_content += f"\n# Added by n8n-installer\nSECRET_KEY={secret_key}\n" + # Change NGINX_PORT to prevent port 80 conflict + if "NGINX_PORT=" in dify_env_content: + # Find the NGINX_PORT line and replace it + lines = dify_env_content.split('\n') + for i, line in enumerate(lines): + if line.strip().startswith("NGINX_PORT="): + lines[i] = f"NGINX_PORT={dify_nginx_port}" + print(f"Changed Dify NGINX_PORT from 80 to {dify_nginx_port} to prevent port conflict") + break + dify_env_content = '\n'.join(lines) + else: + # Append NGINX_PORT configuration + dify_env_content += f"\n# Port configuration to prevent conflicts (added by n8n-installer)\nNGINX_PORT={dify_nginx_port}\n" + print(f"Added Dify NGINX_PORT={dify_nginx_port} to prevent port 80 conflict") + # Write the updated content back with open(dify_env_path, "w") as f: f.write(dify_env_content) - print("Successfully copied Dify .env.example and added SECRET_KEY") + print("Successfully copied Dify .env.example and added SECRET_KEY and port configuration") else: print("Warning: DIFY_SECRET_KEY not found in main .env file") else: # Fallback: create basic .env if .env.example doesn't exist print("Warning: Dify .env.example not found, creating basic .env configuration...") secret_key = env_values.get("DIFY_SECRET_KEY", "") + dify_nginx_port = env_values.get("DIFY_NGINX_PORT", "8080") dify_env_content = f"""# Dify Environment Configuration # Generated from n8n-installer main .env # Core Dify Configuration SECRET_KEY={secret_key} + +# Port configuration to prevent conflicts (added by n8n-installer) +NGINX_PORT={dify_nginx_port} """ with open(dify_env_path, "w") as f: f.write(dify_env_content) - print("Created basic Dify .env configuration") + print(f"Created basic Dify .env configuration with NGINX_PORT={dify_nginx_port}") except Exception as e: print(f"Error preparing Dify .env configuration: {e}")