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

相关推荐
zhanghaha13148 小时前
HTML系列教程:3_HTML 基础标签 — 标题、段落、超链接、图像
前端·html
李高钢9 小时前
C# WPF Prism 进阶(二):区域(Region)与模块化(Module)
java·前端·数据库
huaiixinsi9 小时前
Docker 负责打包,Kubernetes 负责调度:一文吃透容器化与 K8s 编排
docker·容器·kubernetes
xyphf_和派孔明9 小时前
Vite 与 Webpack 对比及常见面试题
前端·webpack·vite
明月_清风9 小时前
Pi Agent 深度解析:开源极简终端 AI 编码代理的终极指南
前端·后端·ai编程
凌涘9 小时前
Docker 入门:镜像、容器与反向代理
docker
fatcoder9 小时前
玩转Nginx 03 — location 匹配规则:让不同的路径各回各家
前端·后端·nginx
HjhIron9 小时前
前端面试高频考点 —— TS 高级类型 & CSS 三列布局
前端
李剑一9 小时前
《牛来》火了?我用ThreeJs实现了一个简易版的,代码全送给你,文章最后附演示效果
前端
世界哪有真情10 小时前
AI 写代码两年多,我发现自己越来越"看不进去"了
前端·后端·ai编程