Docker nginx容器部署前端项目。

复制代码
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/json;

    sendfile        on;
    
    keepalive_timeout  65;

    server {
        listen       18080;
        # 指定前端项目所在的位置
        location / {
            root /usr/share/nginx/html/hmall-portal;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /api {
            rewrite /api/(.*)  /$1 break;
            proxy_pass http://hm:8080;
        }
    }
    server {
        listen       18081;
        # 指定前端项目所在的位置
        location / {
            root /usr/share/nginx/html/hmall-admin;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /api {
            rewrite /api/(.*)  /$1 break;
            proxy_pass http://hm:8080;
        }
    }
}

1。上面是nginx的配置文件,hm是网络的名称。 /usr/share/nginx/html 是nginx容器内部文件的地址。

2.上传文件到服务器,并且启动的时候,做数据卷映射

3.启动命令

复制代码
docker run -d \
 --name nginx \
-p 18080:18080 \
-p 18081:18081 \
-v  /root/nginx/html:/usr/share/nginx/html \
-v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \
--network heima \
nginx

这里部署了两个前端项目,所以进行两个端口映射18080和18081

然后配置文件和前端文件都需要数据卷映射。

相关推荐
遇见火星18 分钟前
Nginx限流配置:防止接口被刷,服务器稳如泰山
运维·服务器·nginx
sthnyph21 分钟前
docker compose安装redis
redis·docker·容器
爱上好庆祝27 分钟前
学习js的第五天
前端·css·学习·html·css3·js
C澒40 分钟前
IntelliPro 产研协作平台:基于 AI Agent 的低代码智能化配置方案设计与实现
前端·低代码·ai编程
一袋米扛几楼981 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
W.A委员会1 小时前
Docker基本使用流程
运维·docker·容器
网络点点滴1 小时前
前端与后端的区别与联系
前端
EnCi Zheng1 小时前
M5-markconv自定义CSS样式指南 [特殊字符]
前端·css·python
kyriewen2 小时前
你的网页慢,用户不说直接走——前端性能监控教你“读心术”
前端·性能优化·监控
广州华水科技2 小时前
北斗GNSS变形监测在大坝安全监测中的应用与优势分析
前端