Vue前端项目打包

4.1编译打包
npm run build在这里插入图片描述

4.2 前端项目 nginx的配置文件default.conf 和 dockerfile
default.conf
upstream wms-app {
server 192.168.14.3:3666 ;
server 192.168.14.3:3777 ;
}
server {
listen 80;
listen [::]:80;
server_name localhost;

access_log  /var/log/nginx/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html; #解决单页面找不到路径问题 404
}

location /api/ {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'POST,GET,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization'; #跨域设置
        proxy_pass http://wms-app ;  #可以配置多个下游服务,具有负载功能
        #proxy_pass http://192.168.14.3:3666; #仅配置一个下游服务,不具有负载均衡能力

}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}

1.root:设置静态根目录为 /usr/share/nginx/html
2. index:设置目录的默认文件为 index.html 、index.htm、index.php
3. try_files:设置文件查找规则为 $uri $uri/ /index.html。即3个规则,先从 $uri 查找,再从 u r i / 目录中查找,最后查找 / i n d e x . h t m l 。
dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
#COPY default.conf /etc/nginx/conf.d/
COPY dist/ /usr/share/nginx/html/

4.3 构建镜像
docker build -t web:v1 .

4.4 运行
docker run -it -p 8086:80 web:v1

相关推荐

  1. idea编译打包前端vue项目

    2024-04-01 01:58:01       32 阅读
  2. webpack 打包前端项目

    2024-04-01 01:58:01       29 阅读
  3. webpack 打包前端项目

    2024-04-01 01:58:01       32 阅读
  4. Webpack打包vue项目

    2024-04-01 01:58:01       37 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-01 01:58:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-01 01:58:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-01 01:58:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-01 01:58:01       20 阅读

热门阅读

  1. python装饰器的使用

    2024-04-01 01:58:01       17 阅读
  2. COMP2017 9017

    2024-04-01 01:58:01       14 阅读
  3. [TS面试]TS中如何设计Class声明

    2024-04-01 01:58:01       14 阅读
  4. 算法练习----力扣每日一题------3

    2024-04-01 01:58:01       20 阅读
  5. 数据集视频编码(自用)

    2024-04-01 01:58:01       17 阅读
  6. 对 CSS Sprites(精灵图) 的理解

    2024-04-01 01:58:01       19 阅读
  7. v-for 中的模板引用

    2024-04-01 01:58:01       20 阅读
  8. Nginx入门 -- 理解Nginx基础概念:连接(Connection)

    2024-04-01 01:58:01       21 阅读
  9. LeetCode342. 4的幂

    2024-04-01 01:58:01       18 阅读