CentOS7 Docker Nginx部署及运行实例分析
发布时间 - 2023-05-14 00:00:00 点击率:次1、资源准备
dockerfile文件
# "ported" by adam millerfrom # https://github.com/fedora-cloud/fedora-dockerfiles # # originally written for fedora-dockerfiles by # scollier from centos:centos7 maintainer the centos project run yum -y update; yum clean all run yum -y install epel-release tar ; yum clean all run yum -y install nginx ; yum clean all add nginx.conf /opt/deploy/nginx/nginx.conf run echo "daemon off;" >> /opt/deploy/nginx/nginx.conf #run curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ # | tar -xz -c /usr/local/nginx/html \ # --strip-components=1 #run sed -i -e 's/apache/nginx/g' -e '/apache_pb.gif/d' \ # /usr/local/nginx/html/index.html expose 80 #cmd [ "/usr/local/nginx/sbin" ]
注意:路径需要在系统上面存在以及对应
nginx.conf文件
# for more information on configuration, see:
# * official english documentation: http://nginx.org/en/docs/
# * official russian documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /usr/logs/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/logs/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# load modular configuration files from the /etc/nginx/conf.d directory.
# see http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
#include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
autoindex on;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /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;
#}
}
# another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# location / {
# }
#}
# https server
#
#server {
# listen 443;
# server_name localhost;
# root html;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols sslv2 sslv3 tlsv1;
# ssl_ciphers high:!anull:!md5;
# ssl_prefer_server_ciphers on;
# location / {
# }
#}
}注意:路径需要在系统上面存在以及对应
2、执行构建镜像命令
复制代码 代码如下:
[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 .
执行结果截图:
3、查看镜像是否安装构建
成功 docker images
4、创建容器 docker run -i -t -d -p 192.168.32.129:81:80 os7/nginx /bin/bash
注意:192.168.32.129这个ip的话,则需要在/etc/hosts中添加
192.168.32.129 localhost
5、查看容器是否创建成功并启动 docker ps
6、测试是否成功访问 curl http://192.168.32.129:81
会出现这个拒绝连接,那怎么办呢?有办法解决的,我们先进入该容器里面
7、进入容器 docker exec -i -t small_hodgkin /bin/sh
8、接着在容器里面执行(直接输入即可)
nginx
9、在容器外面执行 curl http://192.168.32.129:81
成功了。
10、再到虚拟机外面通过浏览器访问
# docker
# nginx
# centos7
# bash
# cURL
# http
# 镜像
# 要在
# 再到
# 则需
# 直接输入
# user
# worker_processes
# ru
# en
# docs
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
Laravel如何处理和验证JSON类型的数据库字段
使用C语言编写圣诞表白程序
如何在IIS服务器上快速部署高效网站?
Laravel如何生成PDF或Excel文件_Laravel文档导出工具与使用教程
Laravel辅助函数有哪些_Laravel Helpers常用助手函数大全
如何在局域网内绑定自建网站域名?
Laravel怎么自定义错误页面_Laravel修改404和500页面模板
如何用ChatGPT准备面试 模拟面试问答与职场话术练习教程
Laravel Eloquent模型如何创建_Laravel ORM基础之Model创建与使用教程
Win11怎么设置默认图片查看器_Windows11照片应用关联设置
怎么制作一个起泡网,水泡粪全漏粪育肥舍冬季氨气超过25ppm,可以有哪些措施降低舍内氨气水平?
Midjourney怎样加参数调细节_Midjourney参数调整技巧【指南】
Laravel Telescope怎么调试_使用Laravel Telescope进行应用监控与调试
Laravel的辅助函数有哪些_Laravel常用Helpers函数提高开发效率
Laravel Asset编译怎么配置_Laravel Vite前端构建工具使用
Laravel Octane如何提升性能_使用Laravel Octane加速你的应用
高端网站建设与定制开发一站式解决方案 中企动力
香港服务器部署网站为何提示未备案?
如何在阿里云购买域名并搭建网站?
Python结构化数据采集_字段抽取解析【教程】
Laravel如何实现事件和监听器?(Event & Listener实战)
如何在阿里云高效完成企业建站全流程?
武汉网站设计制作公司,武汉有哪些比较大的同城网站或论坛,就是里面都是武汉人的?
Python制作简易注册登录系统
如何在云主机快速搭建网站站点?
Laravel如何实现本地化和多语言支持_Laravel多语言配置与翻译文件管理
详解Oracle修改字段类型方法总结
Laravel如何实现多语言支持_Laravel本地化与国际化(i18n)配置教程
详解MySQL数据库的安装与密码配置
Linux系统命令中tree命令详解
HTML5空格和nbsp有啥关系_nbsp的作用及使用场景【说明】
极客网站有哪些,DoNews、36氪、爱范儿、虎嗅、雷锋网、极客公园这些互联网媒体网站有什么差异?
阿里云高弹*务器配置方案|支持分布式架构与多节点部署
JS去除重复并统计数量的实现方法
🚀拖拽式CMS建站能否实现高效与个性化并存?
Laravel如何生成和使用数据填充?(Seeder和Factory示例)
laravel怎么为API路由添加签名中间件保护_laravel API路由签名中间件保护方法
php嵌入式断网后怎么恢复_php检测网络重连并恢复硬件控制【操作】
ChatGPT 4.0官网入口地址 ChatGPT在线体验官网
免费制作统计图的网站有哪些,如何看待现如今年轻人买房难的情况?
iOS验证手机号的正则表达式
如何在IIS中配置站点IP、端口及主机头?
Laravel如何处理文件上传_Laravel Storage门面实现文件存储与管理
邀请函制作网站有哪些,有没有做年会邀请函的网站啊?在线制作,模板很多的那种?
Linux虚拟化技术教程_KVMQEMU虚拟机安装与调优
Win11摄像头无法使用怎么办_Win11相机隐私权限开启教程【详解】
Laravel软删除怎么实现_Laravel Eloquent SoftDeletes功能使用教程
Laravel 419 page expired怎么解决_Laravel CSRF令牌过期处理
Javascript中的事件循环是如何工作的_如何利用Javascript事件循环优化异步代码?
Laravel如何部署到服务器_线上部署Laravel项目的完整流程与步骤

