From 6a88ec0d46a3345bafd948a1848cfb3449b3c6e3 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 24 May 2026 14:33:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E4=BF=AE=E5=A4=8D=20Docker=20?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E4=B8=A4=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 后端 Dockerfile 开启 CGO(go-sqlite3 依赖),安装 gcc/musl-dev 2. nginx 添加 /auth/ 反向代理,修复注册登录 405 错误 --- backend/Dockerfile | 4 ++-- docs/api.md | 2 +- frontend/nginx.conf | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 3eb041b..2e1fe86 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,13 +2,13 @@ FROM golang:1.26-alpine AS builder RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories -RUN apk add --no-cache git +RUN apk add --no-cache git gcc musl-dev WORKDIR /src COPY go.mod go.sum ./ RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /bin/gen2d ./cmd/main.go +RUN CGO_ENABLED=1 GOOS=linux go build -o /bin/gen2d ./cmd/main.go # ---- Runtime Stage ---- FROM alpine:3.20 diff --git a/docs/api.md b/docs/api.md index 2a508ee..5c6f9ba 100644 --- a/docs/api.md +++ b/docs/api.md @@ -57,7 +57,7 @@ Token 过期或无效时返回: ## 用户认证 -> **注意:** 后端代码实际注册路径为 `/auth/*`(非 `/api/v1/auth/*`),前端 Vite 代理已配置 `/auth` 转发。 +> **注意:** 后端代码实际注册路径为 `/auth/*`(非 `/api/v1/auth/*`),前端 Vite 代理及 nginx 均已配置 `/auth` 转发。 | 状态 | 方法 | 路径 | 说明 | |------|------|------|------| diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 6eb4544..0a6a0c8 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -18,4 +18,13 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + + # 反向代理 /auth 到后端服务 + location /auth/ { + proxy_pass http://backend:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } }