Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa9aece

Browse files
authored
feat: Add docker support to enhance project scalability and deployment efficiency (#43)
* docs: update readme Install and use * feat: add docker * feat: add nginx.conf * fix: change Traditional Chinese to Simplified Chinese
1 parent a487141 commit aa9aece

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules
2+
/.git
3+
/.gitignore
4+
/.vscode
5+
/.DS_Store
6+
/*.md
7+
/dist
8+

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ pnpm build
7171

7272
```
7373

74+
You can deploy **nova-admin** in a production environment using docker-compose.
75+
```bash
76+
# Build product
77+
docker compose -f docker-compose.product.yml up --build -d
78+
```
79+
> The nginx.conf provided is for reference only. You can adjust it according to your own needs.
80+
7481
## Related projects
7582

7683
- [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (under development) Nova-Admin supporting background project based on TS, NestJs, typeorm

README.zh-CN.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ pnpm build
7171

7272
```
7373

74+
在生产环境也可以使用 docker-compose 部署 **nova-admin**
75+
```bash
76+
# Build product
77+
docker compose -f docker-compose.product.yml up --build -d
78+
```
79+
> 关于 nginx.conf 只供参考,你可以根据自己的需求进行调整。
80+
7481
## 相关项目
7582

7683
- [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (开发中)基于TS, NestJs, typeorm的Nova-Admin配套后台项目

docker-compose.product.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
nove-admin:
3+
build:
4+
context: .
5+
dockerfile: ./docker/dockerfile.product
6+
container_name: nove-admin
7+
ports:
8+
- 80:80

docker/dockerfile.product

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:20-slim AS base
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /app
6+
WORKDIR /app
7+
8+
FROM base AS prod-deps
9+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
10+
11+
FROM base AS builder
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13+
RUN pnpm run build
14+
15+
FROM nginx:1.23.1-alpine
16+
17+
WORKDIR /www
18+
19+
COPY --from=builder /app/dist/ .
20+
21+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
22+
23+
EXPOSE 80

nginx.conf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
5+
# 启用 gzip 压缩
6+
gzip on;
7+
gzip_vary on;
8+
gzip_min_length 10240;
9+
gzip_proxied expired no-cache no-store private auth;
10+
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
11+
gzip_disable "MSIE [1-6]\.";
12+
13+
# 设定 MIME types
14+
include /etc/nginx/mime.types;
15+
16+
# 基本安全设定
17+
add_header X-Frame-Options "SAMEORIGIN";
18+
add_header X-XSS-Protection "1; mode=block";
19+
add_header X-Content-Type-Options "nosniff";
20+
21+
# 增加伺服器效能的配置
22+
client_max_body_size 100M;
23+
client_body_buffer_size 128k;
24+
proxy_connect_timeout 90;
25+
proxy_send_timeout 90;
26+
proxy_read_timeout 90;
27+
proxy_buffer_size 4k;
28+
proxy_buffers 4 32k;
29+
proxy_busy_buffers_size 64k;
30+
31+
location / {
32+
root /www;
33+
index index.html;
34+
try_files $uri $uri/ /index.html;
35+
36+
# 设定快取控制
37+
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
38+
expires 30d;
39+
add_header Cache-Control "public, no-transform";
40+
}
41+
42+
# 动态内容不快取
43+
location = /index.html {
44+
add_header Cache-Control "no-store, no-cache, must-revalidate";
45+
add_header Pragma "no-cache";
46+
expires -1;
47+
}
48+
49+
# 错误处理
50+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
51+
proxy_intercept_errors on;
52+
53+
# 基本的代理设定
54+
proxy_set_header Host $host;
55+
proxy_set_header X-Real-IP $remote_addr;
56+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57+
proxy_set_header X-Forwarded-Proto $scheme;
58+
}
59+
60+
# 禁止访问隐藏文件
61+
location ~ /\. {
62+
deny all;
63+
access_log off;
64+
log_not_found off;
65+
}
66+
}

0 commit comments

Comments
 (0)