chore: 删除不再需要的docker相关文件和参考代码
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# 参考代码
|
||||
|
||||
部分代码片段,供参考。
|
||||
@@ -1,31 +0,0 @@
|
||||
# 依赖目录
|
||||
node_modules
|
||||
|
||||
# 版本控制
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# 构建产物
|
||||
/dist
|
||||
|
||||
# 开发工具配置
|
||||
.vscode/
|
||||
.idea/
|
||||
.trae/
|
||||
.cursor/
|
||||
|
||||
# 其他配置文件
|
||||
.github/
|
||||
.husky/
|
||||
|
||||
# 日志文件
|
||||
logs/
|
||||
|
||||
# 缓存文件
|
||||
.cache/
|
||||
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# 操作系统文件
|
||||
.DS_Store
|
||||
@@ -1,38 +0,0 @@
|
||||
# 使用 node:24-alpine 作为基础镜像,固定版本+减少体积
|
||||
FROM node:24-alpine AS builder
|
||||
|
||||
# 在容器中创建目录
|
||||
WORKDIR /app
|
||||
|
||||
# 安装pnpm(使用 npm 的 --global-style 可以减少依赖安装体积)
|
||||
RUN npm install -g pnpm@10.10.0 --global-style
|
||||
# 设置pnpm镜像源
|
||||
RUN pnpm config set registry https://registry.npmmirror.com
|
||||
# 复制依赖文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
# 先复制scripts目录,因为prepare脚本需要用到其中的文件
|
||||
COPY scripts ./scripts
|
||||
# 安装依赖,但跳过prepare脚本(这一步会缓存,只有 package.json 或 pnpm-lock.yaml 变化时才会重新运行)
|
||||
RUN pnpm install --ignore-scripts --frozen-lockfile
|
||||
# 手动执行我们需要的docker:prepare脚本
|
||||
RUN pnpm run docker:prepare
|
||||
# 复制其余源代码
|
||||
COPY . .
|
||||
# 构建项目
|
||||
RUN pnpm run build
|
||||
|
||||
|
||||
# 使用nginx作为服务
|
||||
FROM nginx:1.29.1-alpine3.22 AS production-stage
|
||||
|
||||
# 将构建好的项目复制到nginx下
|
||||
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
|
||||
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
# 启动nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -1,28 +0,0 @@
|
||||
## Docker
|
||||
|
||||
根据提供的 `Dockerfile`,可以通过以下步骤构建并运行镜像:
|
||||
|
||||
### 1. 构建Docker镜像
|
||||
|
||||
在项目根目录执行以下命令:
|
||||
|
||||
- `-t unibest:v1-2025091701`:为镜像指定名称和标签,YYYYMMDD+编号
|
||||
- `.`:表示使用当前目录的Dockerfile
|
||||
|
||||
```bash
|
||||
docker build -t unibest:v1-2025091701 .
|
||||
docker build -t unibest:v1-2025091702 .
|
||||
```
|
||||
### 2. 运行Docker容器
|
||||
使用以下命令运行容器:
|
||||
|
||||
```bash
|
||||
docker run -d --name unibest-v1-2025091701 -p 80:80 unibest:v1-2025091701
|
||||
docker run -d --name unibest-v1-2025091702 -p 80:80 unibest:v1-2025091702
|
||||
```
|
||||
|
||||
- `-d`:表示在后台运行容器
|
||||
- `-p 80:80`:将容器的80端口映射到主机的80端口
|
||||
- `--name unibest-v1-2025091701`:为容器指定一个名称
|
||||
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
# 配置工作进程数,通常设置为 CPU 核心数
|
||||
worker_processes auto;
|
||||
|
||||
# 错误日志配置
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
# 开启多路复用
|
||||
use epoll;
|
||||
}
|
||||
|
||||
# 文件描述符限制 - 移到这里,在http块之前
|
||||
worker_rlimit_nofile 65535;
|
||||
|
||||
http {
|
||||
# 日志格式定义
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
# 访问日志配置
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
# 高效文件传输设置
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
|
||||
# 连接超时设置
|
||||
keepalive_timeout 65;
|
||||
keepalive_requests 100;
|
||||
|
||||
# gzip 压缩优化
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
gzip_min_length 1000;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
# 增加更多文件类型
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
|
||||
|
||||
# 全局设置
|
||||
# 合理限制请求体大小,根据实际需求调整
|
||||
client_max_body_size 10m;
|
||||
client_body_buffer_size 128k;
|
||||
client_header_timeout 60s;
|
||||
client_body_timeout 60s;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
gunzip on;
|
||||
gzip_static always;
|
||||
include /etc/nginx/mime.types;
|
||||
absolute_redirect off;
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# 安全相关响应头
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
# 根据实际情况调整 CSP
|
||||
# add_header Content-Security-Policy "default-src 'self'";
|
||||
|
||||
# 处理 SPA 应用路由
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
# HTML 和 JSON 文件 - 短缓存策略
|
||||
location ~ .*\.(html|json)$ {
|
||||
add_header Cache-Control "public, max-age=300, must-revalidate";
|
||||
}
|
||||
|
||||
# 静态资源 - 长缓存策略
|
||||
location ~ .*\.(jpg|jpeg|png|gif|bmp|webp|svg|ico|ttf|woff|woff2|eot|mp4|mp3|swf)$ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
expires 365d;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# JS 和 CSS - 带版本号的长缓存
|
||||
location ~ .*\.(js|css)$ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
expires 365d;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# 接口转发 - 替换为实际后端地址
|
||||
# location ^~ /fg-api {
|
||||
# proxy_http_version 1.1;
|
||||
# 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;
|
||||
# proxy_set_header Host $host;
|
||||
|
||||
# # 后端是HTTPS时的必要配置
|
||||
# proxy_ssl_server_name on;
|
||||
# proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
||||
# proxy_ssl_session_reuse on;
|
||||
|
||||
# # 对于生产环境,应该尽量使用有效的证书而不是依赖``proxy_ssl_verify off;`` ,因为这会带来安全风险
|
||||
# proxy_ssl_verify off;
|
||||
|
||||
# # TODO:替换为实际后端服务地址
|
||||
# # 注意在URL末尾添加了斜杠,这样Nginx会去掉 /fg-api 前缀
|
||||
# # 前端请求 http://your-domain.com/fg-api/users 转发到 https://ukw0y1.laf.run/users
|
||||
# proxy_pass https://ukw0y1.laf.run/;
|
||||
|
||||
# # 上面一行的效果与下面2行一样的效果,都是为了去掉 /fg-api 前缀
|
||||
# # 显式移除/fg-api前缀
|
||||
# # rewrite ^/fg-api(.*)$ $1 break;
|
||||
# # 域名末尾不需要斜杠了
|
||||
# # proxy_pass https://ukw0y1.laf.run;
|
||||
|
||||
# proxy_connect_timeout 60s;
|
||||
# proxy_send_timeout 60s;
|
||||
# proxy_read_timeout 60s;
|
||||
|
||||
# proxy_buffers 8 32k;
|
||||
# proxy_buffer_size 64k;
|
||||
# proxy_busy_buffers_size 128k;
|
||||
|
||||
# proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
|
||||
# }
|
||||
|
||||
# 错误页面配置
|
||||
error_page 404 /index.html;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
# 禁止访问隐藏文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user