Docker Nginx 运行多个前端项目

  • 运行Nginx容器:

    docker run -itd --name nginxWeb -p 80:80 -p 8081:8081 nginx:latest

    --name是容器名称变量,nginx是创建容器的名称
    -p 端口映射,新增一个8081的端口映射,如果配置的是域名可以公用80端口

  • copy 打包后的前端项目到容器的/usr/share/nginx目录下,拷贝后的目录一定要是:/usr/share/nginx/html否则无法运行

    docker cp D:..\dist\build\html nginx:/usr/share/nginx
    docker cp D:..\dist\build\web2 nginx:/usr/share/nginx

  • nginx配置:目录:etc/nginx/conf.d 新增web.conf配置

    server {
    listen 8081;
    listen [::]:8081;
    server_name localhost;//这里可以直接填写域名

    复制代码
      #access_log  /var/log/nginx/host.access.log  main;
    
      location / {
          root   /usr/share/nginx/web2;
          index  index.html;
      }
    
      #error_page  404              /404.html;
    
      # redirect server error pages to the static page /50x.html
      #
    
    
      # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      #
      #location ~ \.php$ {
      #    proxy_pass   http://127.0.0.1;
      #}
    
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      #location ~ \.php$ {
      #    root           html;
      #    fastcgi_pass   127.0.0.1:9000;
      #    fastcgi_index  index.php;
      #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
      #    include        fastcgi_params;
      #}
    
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #    deny  all;
      #}

    }

  • 进入容器

    docker exec -it 容器名称/id bash

进入容器后运行:

复制代码
nginx -s reload

浏览器打开:http://localhost/#/http://localhost:8081/#/访问应用

相关推荐
再玉米地里吃过亏26 分钟前
ONENET平台API鉴权错误
前端
网络点点滴28 分钟前
Vue3中Suspense的使用
前端·javascript·vue.js
饼干哥哥1 小时前
搭建一个云端Skills系统,随时随地记录TikTok爆款
前端·后端
wuxingge1 小时前
docker部署solara音乐播放器
docker·容器
wenlonglanying1 小时前
nginx 代理 redis
运维·redis·nginx
酉鬼女又兒1 小时前
零基础快速入门前端Web存储(sessionStorage & localStorage)知识点详解与蓝桥杯考点应用(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·javascript·职场和发展·蓝桥杯·html
DanCheOo1 小时前
# 从"会用 AI"到"架构 AI":高级前端的认知升级
前端·ai编程
社恐的下水道蟑螂1 小时前
前端面试必问 Git 通关指南:常用命令速查 + merge/rebase 深度辨析,看完再也不慌
前端·git·面试
None3211 小时前
NestJS 流式文件上传实践:从 Multer 到 Busboy 的进阶之路
前端·后端
海浪浪2 小时前
Symbol 产生的背景以及应用场景
前端·javascript