diff --git a/Makefile b/Makefile index 74d1e85d..b8d414a6 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ deps: # Build for production build-prod: - GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o $(BINARY_NAME) $(MAIN_PATH) + GOOS=linux go build -installsuffix cgo -ldflags="-w -s" -o $(BINARY_NAME) $(MAIN_PATH) clean-db: @echo "Cleaning database..." diff --git a/docker-compose.yml b/docker-compose.yml index 9499cffe..913425cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,12 @@ services: volumes: - data-files:/data/files - ./config/config.yaml:/app/config/config.yaml + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s environment: - COS_SECRET_ID=${COS_SECRET_ID} - COS_SECRET_KEY=${COS_SECRET_KEY} @@ -102,7 +108,8 @@ services: ports: - "${FRONTEND_PORT:-80}:80" depends_on: - - app + app: + condition: service_healthy networks: - WeKnora-network restart: unless-stopped diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 2e09ed80..9593dbc5 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -2,6 +2,10 @@ server { listen 80; server_name localhost; client_max_body_size 50M; + + # 错误日志配置 + error_log /var/log/nginx/error.log warn; + access_log /var/log/nginx/access.log; # 前端静态文件 location / { @@ -18,6 +22,12 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + # 连接和重试配置 + proxy_connect_timeout 30s; # 连接超时时间 + proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; + proxy_next_upstream_tries 3; # 重试次数 + proxy_next_upstream_timeout 30s; # 重试超时时间 + # SSE 相关配置 proxy_http_version 1.1; # 使用 HTTP/1.1 proxy_set_header Connection ""; # 禁用 Connection: close,保持连接打开 diff --git a/internal/middleware/auth.go b/internal/middleware/auth.go index 7f81ef5b..94513410 100644 --- a/internal/middleware/auth.go +++ b/internal/middleware/auth.go @@ -19,6 +19,7 @@ var noAuthAPI = map[string][]string{ "/api/v1/test-data": {"GET"}, "/api/v1/tenants": {"POST"}, "/api/v1/initialization/*": {"GET", "POST"}, + "/health": {"GET"}, } // 检查请求是否在无需认证的API列表中