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/#/访问应用

相关推荐
蓝婷儿3 分钟前
每天一个前端小知识 Day 28 - Web Workers / 多线程模型在前端中的应用实践
前端
琹箐4 分钟前
Ant ASpin自定义 indicator 报错
前端·javascript·typescript
小小小小小惠8 分钟前
Responsetype blob会把接口接收的二进制文件转换成blob格式
前端·javascript
爱电摇的小码农8 分钟前
【深度探究系列(5)】:前端开发打怪升级指南:从踩坑到封神的解决方案手册
前端·javascript·css·vue.js·node.js·html5·xss
不知疲倦的仄仄30 分钟前
2025最新版Docker讲解/面试/命令/容器化技术
运维·docker·容器
kymjs张涛34 分钟前
零一开源|前沿技术周报 #7
android·前端·ios
爱编程的喵39 分钟前
React入门实战:从静态渲染到动态状态管理
前端·javascript
Tttian6221 小时前
npm init vue@latestnpm error code ETIMEDOUT
前端·vue.js·npm
患得患失9491 小时前
【前端】【组件库开发】【原理】【无框架开发】现代网页弹窗开发指南:从基础到优化
前端
运维咖啡吧1 小时前
给朋友们分享个好消息 7天时间23.5k
前端·程序员·ai编程