Compare commits

..

10 Commits

6 changed files with 39 additions and 3 deletions

View File

@@ -25,11 +25,9 @@ services:
- app-network
nginx:
image: nginx:stable-alpine
build: ./nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- frontend
- backend

View File

@@ -23,6 +23,9 @@ FROM nginx:stable-alpine as production-stage
# 复制构建好的文件到Nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 复制Nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf
# 暴露80端口
EXPOSE 80

21
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,21 @@
# 用户连接数
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
# 设置根目录
root /usr/share/nginx/html;
index index.html;
# 处理SPA路由
location / {
try_files $uri $uri/ /index.html;
}
}
}

View File

@@ -82,6 +82,9 @@ const handleConfirm = async () => {
if (!createData.password) {
throw new Error('密码不能为空')
}
if (!/^\d{6,}$/.test(createData.password)) {
throw new Error('密码必须为6位或以上的数字')
}
await userService.createUser({
username: createData.username,
password: createData.password,

11
nginx/Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
# 使用Nginx作为基础镜像
FROM nginx:stable-alpine
# 复制Nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf
# 暴露80端口
EXPOSE 80
# 启动Nginx
CMD ["nginx", "-g", "daemon off;"]