添加Docker配置文件:docker-entrypoint.sh、Dockerfile和nginx.conf

This commit is contained in:
root 2025-12-07 14:25:59 +08:00
parent cfe07aa32e
commit d77d2511cd
3 changed files with 68 additions and 3 deletions

View File

@ -1,5 +1,32 @@
FROM nginx
RUN mkdir /app
FROM node:16-alpine
# 安装Node.js依赖和构建工具
WORKDIR /app
# 先复制package.json和package-lock.json
COPY ./web/package*.json ./
# 安装依赖
RUN npm install
# 复制项目文件
COPY ./index.html /app/
COPY ./dist /app/dist/
COPY nginx.conf /etc/nginx/nginx.conf
COPY ./web /app/web/
# 复制nginx配置
COPY nginx.conf /etc/nginx/nginx.conf
# 安装nginx
RUN apk add --no-cache nginx
# 创建nginx和app目录
RUN mkdir -p /var/www/html /var/log/nginx /var/lib/nginx/tmp /run/nginx
# 复制启动脚本
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
EXPOSE 80 3456
CMD ["/docker-entrypoint.sh"]

18
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/sh
# 启动AI服务
node /app/web/scripts/ai.js &
AI_PID=$!
# 启动nginx
nginx -g 'daemon off;' &
NGINX_PID=$!
# 等待任意一个进程退出
wait $AI_PID
EXIT_CODE=$?
# 清理:停止另一个进程
kill $NGINX_PID 2>/dev/null || true
exit $EXIT_CODE

View File

@ -14,14 +14,34 @@ http {
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
upstream ai_backend {
server localhost:3456;
}
server {
listen 80;
server_name localhost;
# 前端静态文件
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
# AI后端服务反向代理
location /ai/ {
proxy_pass http://ai_backend;
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;
# SSE支持
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_http_version 1.1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;