当前位置: 首页 > article >正文

docker容器安装nginx

docker安装nginx部署前端项目

拉取镜像

docker pull nginx:1.24.0

运行容器

docker run --name nginx -p 80:80 -d nginx:1.24.0

创建本地挂载的目录

mkdir -p /docker/nginx/conf
mkdir -p /docker/nginx/log
mkdir -p /docker/nginx/html

复制运行的nginx配置到宿主机上

将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /docker/nginx/conf/nginx.conf
将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /docker/nginx/conf/conf.d
将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /docker/nginx/
将容器中的日志log文件夹复制到宿主机
docker cp nginx:/var/log/nginx/ /docker/nginx/log

上述命令执行完毕删除运行的容器

docker stop 容器id
docker rm 容器id

正式运行

docker run  -p 80:80 -p 5010:5010   --restart=always --name nginxWeb -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/conf/conf.d:/etc/nginx/conf.d -v /docker/nginx/log:/var/log/nginx -v /docker/nginx/html:/usr/share/nginx/html -d nginx:1.24.0;

修改配置文件

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/build;
        index  index.html index.htm;
         try_files   $uri   $uri/  /index.html;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/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;
    #}
}

server {
    listen       5010;
    listen  [::]:5010;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/dist;
        index  index.html index.htm;
         try_files   $uri   $uri/  /index.html;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/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 restart id

http://www.kler.cn/news/319403.html

相关文章:

  • 如何在 Linux 中管理和清理日志文件( `find` 命令按时间批量删除日志)
  • Unity DOTS系列之Struct Change核心机制分析
  • 大模型-模型预训练-训练过程优化配置
  • 【鸿蒙HarmonyOS NEXT】数据存储之分布式键值数据库
  • 克里金插值算法文件
  • react学习笔记一:react介绍
  • Linux:路径末尾加/和不加/的区别
  • C#版Halcon:HalconDotNet最详细最全面教程(万字详细总结)
  • 算法-回溯
  • 【java入门】JDK的下载安装与环境配置,最新最详细教程!
  • ubuntu错误GPG error: http://repo.mysql.com/apt/ubuntu noble InRelease
  • 01-ZYNQ linux开发环境安装,基于Petalinux2023.2和Vitis2023.2
  • Python pyppeteer 与playwright 模拟浏览器请求 部署服务器遇到的坑
  • php发送邮箱教程:如何实现邮件发送功能?
  • 算法记录——链表
  • 【Linux基础IO】深入解析Linux基础IO缓冲区机制:提升文件操作效率的关键
  • MySQL—存储过程详解
  • 望繁信科技受邀出席ACS2023,为汽车行业数智化护航添翼
  • vue3自动暴露element-plus组件的ref
  • C# 找到给定点集的简单闭合路径(Find Simple Closed Path for a given set of points)
  • 203. 移除链表元素
  • David律所代理Jose Martin幽默水果版权首发维权,尚未TRO
  • MySQL安装教程
  • 240922-MacOS终端访问硬盘
  • C++_22_异常
  • C++:模版初阶
  • 手把手搞定VMware 的CentOS硬盘扩容
  • Unity 设计模式 之 行为型模式 -【中介者模式】【迭代器模式】【解释器模式】
  • 使用sqoop报错
  • Qt网络通信之TCP