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

相关推荐
雨季mo浅忆2 分钟前
记录利用Cursor快速实现首页数据大屏
前端·ai编程
像我这样帅的人丶你还2 分钟前
🚀🚀🚀2026年还不会Nginx?
前端·nginx
三无推导3 分钟前
One API Docker 部署实战:从 0 搭建多模型统一接口管理平台
运维·ubuntu·docker·容器·github·api网关·token管理
用户059540174465 分钟前
把对话记忆从内存搬到 Redis,长期记忆准确率从 63% 提升到 98%
前端·css
无心使然6 分钟前
Openlayers图层按需分层渲染到不同Canvas画布
前端·vue.js·gis
木斯佳10 分钟前
前端八股文面经大全:字节跳动-存储部门一面(2026-05-29)·面经深度解析
前端·状态模式
ayqy贾杰15 分钟前
有AI了,我当超大头兵还苟得住吗?
前端·后端·架构
Aotman_19 分钟前
JavaScript数组对象中指定字段转换
java·开发语言·前端·javascript·vue.js·前端框架·es6
姓蔡小朋友25 分钟前
React基础
前端·react.js·前端框架
TechWJ29 分钟前
被 Intercom Zendesk收费坑过?我用Chatwoot搭了个免费客服站
docker·ai·开源·客服·chatwoot