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

相关推荐
涉密IT资质笔记39 分钟前
涉密人员脱密期管理规范:期限分级模型、就业限制边界与违规认定标准
java·服务器·前端·网络·数据库
u0111026751 小时前
工具页案例图如何编写 alt让图片说明与处理场景对应
java·前端·javascript·图像处理·人工智能·算法·ai作画
事圆则缓1 小时前
Flutter 状态管理框架对比(五):GetX 的响应式、依赖注册与生命周期
前端·javascript·flutter
广州智造2 小时前
Radioss复合材料使用的单元属性
前端·设计·cad·建模·cae·radioss
张宏宇2 小时前
我把微软开源的 tgrep 做成了本地版 GitHub Code Search:45,629 个文件里搜一次 10ms
前端·后端
huakoh2 小时前
MCP 调用超时后别急着重试:三步读回分清执行状态
前端
打工仔折腾 AI2 小时前
把模型切换交给平台:用蓝耘智能路由搭建商品评论分析工具
java·服务器·前端·后端·python·性能优化·ai agent 实战
不可能片场2 小时前
Electron 发布标题的冒号 击穿命令行解析
前端·electron
reeswell2 小时前
我开源了 inspect-devtools —— 让 AI 终于能"看见"你屏幕上的组件
前端·人工智能
Yuhano3 小时前
W3. 实现Agent工具调用引擎
前端·aigc·ai编程