docker配置修改

This commit is contained in:
Hongying Li
2026-04-12 19:04:31 +08:00
parent 5dd16d9809
commit aed9323a09
3 changed files with 26 additions and 11 deletions

View File

@@ -25,4 +25,4 @@ services:
ports: ports:
# 选择避开了NAS常见的80, 443, 3000, 8080等端口用 8090 作为外部访问端。 # 选择避开了NAS常见的80, 443, 3000, 8080等端口用 8090 作为外部访问端。
# 你可以在NAS路由器或面板中直接访问: http://群晖NAS_IP:8090 # 你可以在NAS路由器或面板中直接访问: http://群晖NAS_IP:8090
- "8090:80" - "8090:8090"

View File

@@ -1,18 +1,13 @@
FROM node:18-alpine AS builder FROM node:18-alpine
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
RUN npm install RUN npm install
COPY . . COPY . .
# NAS部署非常关键的一步由于走Nginx同域反代需将URL置空以使用相对路径避免局域网IP锁死 # NAS部署使用相对路径以便让Vite Preview接管同域/api路由并代理给backend容器
ENV VITE_API_BASE_URL="" ENV VITE_API_BASE_URL=""
RUN npm run build RUN npm run build
FROM nginx:alpine # 安装一个轻量静态服务器 (http-server 或 serve),或者直接使用 vite preview
# 获取vite构件结果 EXPOSE 8090
COPY --from=builder /app/dist /usr/share/nginx/html CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "8090"]
# 覆盖Nginx默认配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露的Web服务器访问端口
EXPOSE 80

View File

@@ -38,4 +38,24 @@ export default defineConfig({
}, },
}, },
}, },
server: {
port: 8090,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://backend:8080',
changeOrigin: true
}
}
},
preview: {
port: 8090,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://backend:8080',
changeOrigin: true
}
}
}
}) })