2-11同步

This commit is contained in:
2026-02-11 14:55:11 +08:00
parent db4a0b109c
commit 8fd739746f
106 changed files with 10981 additions and 15909 deletions

View File

@@ -0,0 +1,63 @@
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
# 升级说明: 从 node:16-alpine 升级到 node:20-alpine
# 原因: 项目已升级到 Node 20需要与本地开发环境保持一致
# 版本选择: 使用 alpine 镜像以减小镜像体积
FROM node:20-alpine AS build
WORKDIR /app
# 只拷贝 package*.json加快缓存命中
# 同时拷贝 package-lock.json 确保依赖版本一致性
COPY package*.json ./
# 配置 npm 使用国内镜像源(腾讯云/阿里云环境)
# 解决从国外 npm 官方源下载依赖速度慢的问题
RUN npm config set registry https://registry.npmmirror.com
# 预先安装依赖
# 临时修复: 使用 npm install 因为 package-lock.json 不在 Git 中
# TODO: 将 package-lock.json 纳入版本控制后改回 npm ci
RUN npm install
# 拷贝全部代码
# 注意: .dockerignore 应排除 node_modules、dist 等目录
COPY . .
# 通过构建参数传入构建环境(如 sit/test/prod
# 默认值: sit (开发测试环境)
ARG BUILD_ENV=sit
ENV BUILD_ENV=${BUILD_ENV}
# 执行构建
# 要求 package.json 中的 script 形如build:sit, build:test, build:prod
# 构建产物输出到 dist/ 目录
RUN npm run build:${BUILD_ENV}
# ===============================
# 2) 生产镜像阶段
# ===============================
# 使用 nginx alpine 镜像作为运行时环境
# alpine 镜像体积小,安全性高,适合生产环境
FROM nginx:1.25-alpine AS runtime
# 清理默认 nginx 静态内容
# 避免与项目文件冲突
RUN rm -rf /usr/share/nginx/html/*
# 从构建阶段拷贝编译产物
# --from=build 指定从构建阶段复制文件
# 只拷贝必要的静态文件,不包含源代码和 node_modules
COPY --from=build /app/dist /usr/share/nginx/html/
# 设置文件权限
# 确保 nginx 用户可以读取静态文件
RUN chmod -R 755 /usr/share/nginx/html
# 暴露 80 端口供外部访问
EXPOSE 80
# 启动 nginx
# -g "daemon off;" 确保 nginx 在前台运行,避免容器退出
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,90 @@
user root;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
# upstream official_backend {
# server localhost:3000 # 机器A的内网地址
# # server 10.0.0.15:3000; # 机器B的内网地址
# }
log_format official_log '客户端IP: $remote_addr | 用户: $remote_user | 时间: $time_local | '
'请求方法和路径: "$request" | 状态码: $status | 响应大小: $body_bytes_sent | '
'来源页面: "$http_referer" | 客户端UA: "$http_user_agent" | '
'上游服务器: $upstream_addr | 上游响应耗时: $upstream_response_time | '
'请求总耗时: $request_time | Host: $host';
# 1. 强制 HTTP 转 HTTPS统一跳转到 lessie.ai
# server {
# listen 80;
# server_name lessie.ai www.lessie.ai;
# return 301 https://lessie.ai$request_uri;
# }
# 2. 统一将 www.lessie.ai 重定向到 lessie.ai
server {
listen 80;
server_name www.lessie.ai;
return 301 http://lessie.ai$request_uri;
}
# 3. 正式服务站点http://lessie.ai
server {
listen 80;
server_name lessie.ai;
# access_log /data/tengine/logs/lessie.ai.official.access.log official_log;
# error_log /data/tengine/logs/lessie.ai.official.error.log;
location /video/ {
# root /data/tengine/html/lessie_official;
root /app/public/vidio;
expires 30d;
add_header Cache-Control "public";
add_header Accept-Ranges bytes;
}
# 反向代理到后端服务器渲染的nuxt项目3000端口
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# 禁止 logo 缓存(默认给用户方形)
location = /favicon.svg {
# 判断 UA如果是 Googlebot改写路径
if ($http_user_agent ~* "(Googlebot|Bingbot)") {
rewrite ^/favicon.svg$ /favicon-google.svg last;
}
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires 0 always;
}
# Googlebot 专用 favicon 文件(圆形图标)
location = /favicon-google.svg {
# root /data/tengine/html/lessie_official;
root /app/public;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires 0 always;
}
}
}

View File

@@ -1,44 +0,0 @@
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
FROM node:20.15.0-alpine AS builder
# 设定工作目录,后续所有指令基于此,避免路径混乱
WORKDIR /app
# 配置npm国内源仅1次配置后续所有npm命令自动复用删除冗余的registry传参
ENV NPM_REGISTRY=https://registry.npmmirror.com/
RUN npm config set registry ${NPM_REGISTRY}
# 先拷贝package.json核心利用Docker层缓存代码不变则不重装依赖
COPY package.json ./
# 安装依赖无需重复写registry已全局配置加快构建
RUN npm install
# 拷贝全部项目代码(放在装依赖后,最大化缓存收益)
COPY . .
# 构建参数默认sitbuild时可通过--build-arg覆盖如prod/test
ARG BUILD_ENV=sit
# 注入环境变量,确保构建脚本能读取到(部分框架需要环境变量透传)
ENV BUILD_ENV=${BUILD_ENV}
# 执行环境构建命令兼容package.json的build:sit/build:test/build:prod
RUN npm run build:${BUILD_ENV}
# ===============================
# 2) 生产镜像阶段轻量Nginx仅保留构建产物
# ===============================
FROM nginx:stable-alpine AS runtime
# 暴露80端口Docker声明方便容器映射不影响实际运行
EXPOSE 80
# 复制自定义Nginx配置解决路由404+禁用所有缓存,核心修正)
COPY ./default.conf /etc/nginx/conf.d/default.conf
# 从构建阶段拷贝最终构建产物到Nginx静态资源根目录
COPY --from=builder /app/dist /usr/share/nginx/html
# Nginx官方镜像默认自动启动nginx无需额外CMD/ENTRYPOINT