Skip to content

Commit

Permalink
feat: 添加Dockerfile和nginx.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
lovezhangchuangxin committed Nov 8, 2024
1 parent 2c8eaba commit 0155212
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 使用官方 Node.js 镜像作为基础镜像
FROM node:18-alpine AS build

# 设置工作目录
WORKDIR /app

# 复制 pnpm 配置文件和 lock 文件
COPY pnpm-lock.yaml ./
COPY .npmrc ./

# 安装 pnpm
RUN npm install -g pnpm

# 复制项目文件
COPY package.json pnpm-workspace.yaml ./
COPY packages/game ./packages/game

# 安装依赖
RUN pnpm install

# 切换到前端项目目录并构建项目
WORKDIR /app/packages/game
RUN pnpm run build

# 使用官方 Nginx 镜像作为基础镜像
FROM nginx:alpine

# 复制构建后的文件到 Nginx 的 html 目录
COPY --from=build /app/packages/game/dist /usr/share/nginx/html

# 复制 Nginx 配置文件
COPY packages/game/nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
18 changes: 18 additions & 0 deletions packages/game/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80; # 监听端口

location / {
root /var/www/html; # 项目路径
index index.html index.htm; # 默认首页
try_files $uri $uri/ /index.html; # 重定向
}

# 配置反向代理
location /api {
proxy_pass http://8.210.206.35:7788; # 代理地址
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;
}
}

0 comments on commit 0155212

Please sign in to comment.