当前位置: 首页 > 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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【数据可视化】Arcgis api4.x 热力图、时间动态热力图、timeSlider时间滑块控件应用 (超详细、附免费教学数据、收藏!)
  • 码点和码元的区别--Unicode标准的【码点】和【码元】
  • 第十一章 【后端】商品分类管理微服务(11.4)——spring-boot-devtools
  • 详细分析uni-app中的页面路由基本知识(附Demo)
  • LeetCode 面试经典150题 67.二进制求和
  • keil的debug功能
  • shell脚本定时任务通知到钉钉
  • 学习threejs,绘制二维线
  • vue2项目实现国际化(若依框架示例)
  • Java 全栈开发中的最佳实践:从前端到后端的完整流程
  • Swing模拟银行柜台系统
  • Dify 中的讯飞星火平台工具源码分析
  • 【嵌入式硬件】续流二极管
  • 流量特征随机ua修改
  • Python 学习之虚拟环境
  • __proto__ 和 prototype的关系
  • 【Redis学习笔记】2018-06-28 redis命令源码学习1
  • 【跃迁之路】【463天】刻意练习系列222(2018.05.14)
  • 【跃迁之路】【669天】程序员高效学习方法论探索系列(实验阶段426-2018.12.13)...
  • 30天自制操作系统-2
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • Angular6错误 Service: No provider for Renderer2
  • iOS高仿微信项目、阴影圆角渐变色效果、卡片动画、波浪动画、路由框架等源码...
  • JavaScript设计模式之工厂模式
  • JS进阶 - JS 、JS-Web-API与DOM、BOM
  • mysql 数据库四种事务隔离级别
  • opencv python Meanshift 和 Camshift
  • PermissionScope Swift4 兼容问题
  • TCP拥塞控制
  • vue数据传递--我有特殊的实现技巧
  • vue自定义指令实现v-tap插件
  • webgl (原生)基础入门指南【一】
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 转载:[译] 内容加速黑科技趣谈
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • PostgreSQL之连接数修改
  • ​1:1公有云能力整体输出,腾讯云“七剑”下云端
  • #13 yum、编译安装与sed命令的使用
  • (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (3)llvm ir转换过程
  • (Java实习生)每日10道面试题打卡——JavaWeb篇
  • (WSI分类)WSI分类文献小综述 2024
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (机器学习-深度学习快速入门)第三章机器学习-第二节:机器学习模型之线性回归
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • (四)Android布局类型(线性布局LinearLayout)
  • (已解决)vue+element-ui实现个人中心,仿照原神
  • *++p:p先自+,然后*p,最终为3 ++*p:先*p,即arr[0]=1,然后再++,最终为2 *p++:值为arr[0],即1,该语句执行完毕后,p指向arr[1]
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET BackgroundWorker
  • .NET COER+CONSUL微服务项目在CENTOS环境下的部署实践
  • .Net Core 微服务之Consul(三)-KV存储分布式锁
  • .NET 材料检测系统崩溃分析
  • .NET 设计模式初探