Skip to content

Commit 174adee

Browse files
committed
增加Docker打包相关配置
1 parent d183a16 commit 174adee

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:lts-alpine
2+
WORKDIR /build
3+
# 设置Node-Sass的镜像地址
4+
RUN npm config set sass_binary_site https://repo.huaweicloud.com/node-sass
5+
# 设置npm镜像
6+
RUN npm config set registry https://repo.huaweicloud.com/repository/npm/
7+
COPY package.json /build/package.json
8+
RUN npm install
9+
COPY ./ /build
10+
RUN npm run build
11+
12+
FROM nginx
13+
RUN mkdir /app
14+
COPY --from=0 /build/dist /app
15+
COPY --from=0 /build/nginx.conf /etc/nginx/nginx.conf
16+
EXPOSE 80

nginx.conf

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
user nginx;
2+
worker_processes 1;
3+
error_log /var/log/nginx/error.log warn;
4+
pid /var/run/nginx.pid;
5+
events {
6+
worker_connections 1024;
7+
}
8+
http {
9+
include /etc/nginx/mime.types;
10+
default_type application/octet-stream;
11+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
12+
'$status $body_bytes_sent "$http_referer" '
13+
'"$http_user_agent" "$http_x_forwarded_for"';
14+
access_log /var/log/nginx/access.log main;
15+
sendfile on;
16+
keepalive_timeout 65;
17+
18+
server {
19+
listen 80;
20+
server_name localhost;
21+
location / {
22+
root /app;
23+
index index.html;
24+
try_files $uri $uri/ /index.html;
25+
}
26+
location /api/
27+
{
28+
proxy_pass http://midway:7001/;
29+
proxy_set_header Host $host;
30+
proxy_set_header X-Real-IP $remote_addr;
31+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32+
proxy_set_header REMOTE-HOST $remote_addr;
33+
34+
#缓存相关配置
35+
#proxy_cache cache_one;
36+
#proxy_cache_key $host$request_uri$is_args$args;
37+
#proxy_cache_valid 200 304 301 302 1h;
38+
39+
#持久化连接相关配置
40+
proxy_connect_timeout 3000s;
41+
proxy_read_timeout 86400s;
42+
proxy_send_timeout 3000s;
43+
#proxy_http_version 1.1;
44+
#proxy_set_header Upgrade $http_upgrade;
45+
#proxy_set_header Connection "upgrade";
46+
47+
add_header X-Cache $upstream_cache_status;
48+
49+
#expires 12h;
50+
}
51+
52+
location /adminer/
53+
{
54+
proxy_pass http://adminer:8080/;
55+
proxy_set_header Host $host;
56+
proxy_set_header X-Real-IP $remote_addr;
57+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
58+
proxy_set_header REMOTE-HOST $remote_addr;
59+
60+
#缓存相关配置
61+
#proxy_cache cache_one;
62+
#proxy_cache_key $host$request_uri$is_args$args;
63+
#proxy_cache_valid 200 304 301 302 1h;
64+
65+
#持久化连接相关配置
66+
proxy_connect_timeout 3000s;
67+
proxy_read_timeout 86400s;
68+
proxy_send_timeout 3000s;
69+
#proxy_http_version 1.1;
70+
#proxy_set_header Upgrade $http_upgrade;
71+
#proxy_set_header Connection "upgrade";
72+
73+
add_header X-Cache $upstream_cache_status;
74+
75+
#expires 12h;
76+
}
77+
78+
error_page 500 502 503 504 /50x.html;
79+
location = /50x.html {
80+
root /usr/share/nginx/html;
81+
}
82+
83+
}
84+
}

0 commit comments

Comments
 (0)