#!/bin/bash # 记录 Dify Nginx 迁进集群后的两处修正。现网文件已经是修正后的内容。 # 再执行时如果解析器已经是 10.96.0.10,脚本直接退出,不改文件。 set -eu CONF=/usr/cluster/dify/src/docker/nginx/conf.d/default.conf TEMPLATE=/usr/cluster/dify/src/docker/nginx/conf.d/default.conf.template python3 - << 'PY' from pathlib import Path paths = [ Path("/usr/cluster/dify/src/docker/nginx/conf.d/default.conf"), Path("/usr/cluster/dify/src/docker/nginx/conf.d/default.conf.template"), ] replacements = { "resolver 127.0.0.11": "resolver 10.96.0.10", "api:5001": "api.dify.svc.cluster.local:5001", "web:3000": "web.dify.svc.cluster.local:3000", "plugin_daemon:5002": "plugin-daemon.dify.svc.cluster.local:5002", } changed = False for path in paths: text = path.read_text(encoding="utf-8") if "resolver 10.96.0.10" in text and "api.dify.svc.cluster.local:5001" in text: print("already", path) continue new = text for old, value in replacements.items(): new = new.replace(old, value) if new != text: path.write_text(new, encoding="utf-8") print("updated", path) changed = True if not changed: print("NGINX_ALREADY_OK") PY echo "Secret nginx-env 的 NGINX_SOCKET_IO_UPSTREAM 应为 api-websocket.dify.svc.cluster.local:5001" echo "Service plugin-daemon 需要同时有 5002 和 5003" echo "改完后 kubectl -n dify rollout restart deploy/nginx"