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

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.lryc.cn/news/450244.html

相关文章:

  • LC记录一:寻找旋转数组最小值、判断旋转数组是否存在给定元素
  • 关于 JVM 个人 NOTE
  • 网络工程和信息安全专业应该考哪些证书?
  • ASP.NET Core 创建使用异步队列
  • 从Linux系统的角度看待文件-基础IO
  • 总结之Coze 是一站式 AI Bot 开发平台——工作流使用及coze总结(三)
  • 汽车线束之故障诊断方案-TDR测试
  • 自己做个国庆75周年头像生成器
  • 2k1000LA loongnix 安装java
  • 中信银行西安分行:构建科技金融体质 做好科技金融“大文章”
  • Linux系统性能调优技巧详解
  • MFC工控项目实例之十九手动测试界面输出信号切换
  • 数据结构——栈的基本操作
  • Chainlit集成LlamaIndex实现知识库高级检索(组合对象检索)
  • 万界星空科技铜拉丝行业MES系统,实现智能化转型
  • ECCV 2024 现场:参会者付高价、跨万里,却无法入场?
  • 使用rsync+jenkins实现服务自动部署全流程
  • python 实现decision tree决策树算法
  • 前端大模型入门:实战篇之Vue3+Antdv+transformers+本地模型实现增强搜索
  • 《向量数据库指南》——Fivetran 的 Partner SDK:构建自定义连接器和目标
  • 微信小程序的 button 标签的边框如何去除?
  • 20240926 关于Goland处理wsl-GOROOT原理猜测
  • Anki 学习日记 - 卡片模版 - 单选ABCD(纯操作)
  • 钉钉x昇腾:用AI一体机撬动企业数字资产智能化
  • 【C/C++】 秋招常考面试题最全总结(让你有一种相见恨晚的感觉)
  • CSS面试真题 part1
  • 针对考研的C语言学习(定制化快速掌握重点5)
  • 构建高效房屋租赁系统:Spring Boot应用
  • 学习单片机编程和硬件设计步骤
  • .net Framework 4.6 WebAPI 使用Hangfire