From fcb11ff4068c46a5d6a8d063e6d5cdf06cf7c4a2 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Wed, 8 Jan 2025 09:20:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20dockerfile=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 32 ++++++++++++++++++++++++++++++++ nginx.conf | 23 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95f55cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# 构建阶段 +FROM node:16-alpine as builder + +# 设置工作目录 +WORKDIR /app + +# 复制 package.json 和 package-lock.json +COPY package*.json ./ + +# 安装依赖 +RUN npm install + +# 复制源代码 +COPY . . + +# 构建项目 +RUN npm run build + +# 生产阶段 +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;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..eacb99e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html index.htm; + + location / { + try_files $uri $uri/ /index.html; + } + + # 配置 API 代理(根据实际需求修改) + location /api { + proxy_pass http://backend-service; # 替换为实际的后端服务地址 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file