新增 docker 文件

This commit is contained in:
andy committed 2026-01-26 16:45:05 +08:00
1 parent 95ed45ffe0
commit 450c6a99cd
8 files changed
+612

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Build output
dist/
dist-ssr/
# IDE
.idea/
.vscode/
*.iml
# OS
.DS_Store
Thumbs.db
# Git
.git/
.gitignore
# Environment
.env.local
.env.*.local
# Docker
Dockerfile
.dockerignore
nginx.conf
# Logs
*.log
logs/
# Temporary files
*.tmp
tmpclaude-*
+34
View File
@@ -0,0 +1,34 @@
# 多阶段构建:构建阶段
FROM node:18-alpine AS builder
WORKDIR /app
# 安装 pnpm
RUN npm install -g pnpm
# 复制 package.json 和 pnpm-lock.yaml
COPY package.json pnpm-lock.yaml ./
# 安装依赖
RUN pnpm install
# 复制源代码
COPY . .
# 构建生产版本
RUN pnpm build
# 运行阶段:使用 Nginx
FROM nginx:alpine
# 从构建阶段复制构建产物到 Nginx
COPY --from=builder /app/dist /usr/share/nginx/html
# 复制自定义 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
+43
View File
@@ -0,0 +1,43 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json;
# 处理前端路由(Vue Router History 模式)
location / {
try_files $uri $uri/ /index.html;
}
# 代理后端 API
location /api/ {
proxy_pass http://crm-backend:8080/api/;
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;
# WebSocket 支持(如果需要)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# 安全头
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}