fix(deploy): 修复 Docker 部署两个问题
1. 后端 Dockerfile 开启 CGO(go-sqlite3 依赖),安装 gcc/musl-dev 2. nginx 添加 /auth/ 反向代理,修复注册登录 405 错误
This commit is contained in:
+2
-2
@@ -2,13 +2,13 @@
|
|||||||
FROM golang:1.26-alpine AS builder
|
FROM golang:1.26-alpine AS builder
|
||||||
|
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
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
|
WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
||||||
|
|
||||||
COPY . .
|
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 ----
|
# ---- Runtime Stage ----
|
||||||
FROM alpine:3.20
|
FROM alpine:3.20
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ Token 过期或无效时返回:
|
|||||||
|
|
||||||
## 用户认证
|
## 用户认证
|
||||||
|
|
||||||
> **注意:** 后端代码实际注册路径为 `/auth/*`(非 `/api/v1/auth/*`),前端 Vite 代理已配置 `/auth` 转发。
|
> **注意:** 后端代码实际注册路径为 `/auth/*`(非 `/api/v1/auth/*`),前端 Vite 代理及 nginx 均已配置 `/auth` 转发。
|
||||||
|
|
||||||
| 状态 | 方法 | 路径 | 说明 |
|
| 状态 | 方法 | 路径 | 说明 |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
|
|||||||
@@ -18,4 +18,13 @@ server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user