【feat】增加docker编译文件和nginx配置文件
This commit is contained in:
parent
d5e836ef51
commit
2ff548f378
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
||||
# 第一阶段
|
||||
# 使用alpine镜像,可以减少构建后docker镜像文件的体积
|
||||
FROM node:14-alpine as build-stage
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /ruoyi_ui
|
||||
# 先copy package.json文件到工作目录,一般我们的项目中依赖是不会变的,这样可以充分利用缓存减少部署时的构建时间
|
||||
COPY package*.json /ruoyi_ui/
|
||||
# 安装node_modules
|
||||
RUN npm config set registry=https://registry.npmmirror.com/
|
||||
RUN npm install
|
||||
# 将所有文件copy到工作目录
|
||||
COPY . /ruoyi_ui
|
||||
# 开始打包
|
||||
RUN npm run build:prod
|
||||
# 第二阶段
|
||||
# 拉取nginx镜像文件
|
||||
FROM nginx
|
||||
# 这里的dist文件就是打包好的文件,project是我们上面设置的工作目录
|
||||
COPY --from=build-stage /ruoyi_ui/dist /usr/share/nginx/ruoyi_ui
|
||||
# default.conf就是我们项目下面的nginx配置文件,我们需要copy到nginx的相应目录
|
||||
COPY --from=0 /ruoyi_ui/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
31
nginx.conf
Normal file
31
nginx.conf
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
server{
|
||||
# 监听本地的80端口
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
# file_upload_size
|
||||
client_max_body_size 10M;
|
||||
# request_size
|
||||
client_body_buffer_size 128k;
|
||||
|
||||
# 对应的打包文件目录
|
||||
#root /usr/share/nginx/food_ui;
|
||||
|
||||
# history路由需要配置,不然刷新会404
|
||||
#try_files $uri $uri/ /index.html;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/ruoyi_ui;
|
||||
try_files $uri $uri/ /index.html; # 按此顺序查找请求的文件
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
# 反向代理,解决跨域
|
||||
location /prod-api/ {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://116.62.56.41:8080/;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user