docker 部署个nginx
docker run \
--name nginx-health-web-pc \
-d -p 6800:80 \
-v /usr/docker/nginx/html:/usr/share/nginx/html \
nginx

  

运行启动不亦乐乎~~~~~这时候忽然前端过来说:“你的nginx里得加一个配置”,顺带还告诉你:“某某某以前就是这样配的",

此时好胜的你当然不能拒绝,但是真正配置起来还是要费点心思的,一般情况下docker启动时进行配置,只要把配置文件的目录挂载出来就可以,简洁方便,但是nginx却是先加载一个主配置文件nginx.conf,在nginx.conf里再加载conf.d目录下的子配置文件(一般最少一个default.conf文件)。这比单独挂载一个目录麻烦了不少,但只要思路清晰,倒也不难。

我们先看挂载好的命令:

启动docker的命令

docker run \
--name myNginx \
-d -p 80:80 \
-v /usr/docker/myNginx/html:/usr/share/nginx/html \
-v /etc/docker/myNginx/nginx.conf:/etc/nginx/nginx.conf:ro \
-v /etc/docker/myNginx/conf.d:/etc/nginx/conf.d \
nginx

  

这里有几个注意事项:

(1)第一个“-v”,是项目位置,把项目放到挂载到的目录下即可;

(2)第二个“-v”,是挂载的主配置文件"nginx.conf",注意"nginx.conf"文件内有一行"include /etc/nginx/conf.d/*.conf;",这个include指向了子配置文件的路径,此处注意include后所跟的路径一定不要出错。

(3)第三个“-v”,把docker内子配置文件的路径也挂载了出来,注意要与(2)中include指向路径一致

(4)重点强调一下,nginx.conf是挂载了一个文件(docker是不推荐这样用的),conf.d挂载的是一个目录

我们先启动一下,可以发现是有问题的,因为配置文件还没有。

配置配置文件

我们找到常规方法安装的nginx时生成的配置文件(一般以“/etc/nginx”下),对应上面启动命令中的挂载位置,把主配置文件nginx.conf放到对应位置“/etc/docker/myNginx/nginx.conf”,把子配置文件“default.conf”放到“/etc/docker/myNginx/conf.d”目录下

重新运行启动命令,发现已经好了,至此docker中的文件已经可以随意配置,跟原生安装是一模一样的

思路:配置时一定要铆定一个思路:挂载出来的文件运行时是要加载到docker进程中去的!这样就不容易混淆。

---------------------------------------------------------------分隔线---------------------------------------------------------------------

贴出我的配置文件:

nginx.conf

 user  root;
worker_processes ; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections ;
} http {
include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout ; autoindex on; #gzip on; include /etc/nginx/conf.d/*.conf; client_max_body_size 100M; client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
}

default.conf

server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
root /usr/nginx/dacheng-wechat-web;
# root /usr/nginx/html;
index index.html index.htm;
autoindex on;
try_files $uri /index/index/page.html;
#try_files $uri /index/map/page.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;
#}
}

  原文地址:https://blog.csdn.net/wangfei0904306/article/details/77623400

【转载】Docker部署nginx并修改配置文件的更多相关文章

  1. Docker部署Nginx并修改配置文件

    Docker部署Nginx并修改配置文件 一.拉取nginx镜像 docker pull nginx 二.在宿主机中创建挂载目录 mkdir -p /data/nginx/{conf,conf.d,h ...

  2. 使用docker部署nginx+tomcat架构(3):使用docker-compose简化部署操作

    经历了之前的两篇,我们已经大体上了解了docker部署容器的过程. 使用docker部署nginx+tomcat架构 使用docker部署nginx+tomcat架构():访问mysql数据库 不过, ...

  3. 使用docker部署nginx+tomcat架构(2):访问mysql数据库

    上一篇完成了通过docker部署nginx+tomcat的基础软件架构,但是距离一个真正可用的软件架构还差得很远.其中最重要的一点是缺少数据库这个角色的存在,那么本篇就来完善这一点. 废话少说,直接进 ...

  4. Docker部署Nginx应用(2)

    Docker部署Nginx应用(2) 1.拉取Nginx镜像 [root@localhost ~]# docker pull nginx Using default tag: latest lates ...

  5. docker(部署常见应用):docker部署nginx

    上回说到centos安装docker. 这次用实战,docker部署运行常见的应用. docker常用命令 参看:docker命令大全.这里不做赘述. docker部署nginx 1.docker h ...

  6. docker 部署nginx 使用keepalived 部署高可用

    一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...

  7. Docker部署nginx,tomcat,es,可视化

    nginx [root@iz2zeaet7s13lfkc8r3e2kz /]# docker pull nginx #下载 Using default tag: latest latest: Pull ...

  8. Docker | 部署nginx服务

    容器时相互隔离的,docker启动的nginx是容器内的服务,不影响我原先服务器上的nginx服务,小伙伴们可大胆尝试 本篇实在linux环境下操作的,主要目的是夺人眼目,对使用Docker部署服务尝 ...

  9. 【原创】大数据基础之Mesos+Marathon+Docker部署nginx

    一 安装 安装docker:https://www.cnblogs.com/barneywill/p/10343091.html安装mesos:https://www.cnblogs.com/barn ...

随机推荐

  1. ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩

    一:MiMEType:一般可以再百度上搜索到相应文件的MiMEType,或是利用c语言的api去获取文件的MiMEType : //对该文件发送一个异步请求,拿到文件的MIMEType - (void ...

  2. Intent七在属性之一:ComponentName 分类: H1_ANDROID 2013-11-10 10:54 1184人阅读 评论(1) 收藏

    注:在<疯狂android讲义>中,此属性称为Component,官方文档中称为ComponentName. 1.The name of the component that should ...

  3. QQ互联API接口失效,第三方网站的死穴

    最近2个月,用开源程序WeCenter搭建了一个社交问答网站. 为了方便用户注册,开通了QQ登录功能. 今天,突然发现QQ互联返回一直出现错误.     度娘了很久,发现大家都遇到这个问题了.Disc ...

  4. Android 比较两个时间段是否有交集或重复

    先看一个例图: 在金山<电池管家>应用中就有一个类似上图这样的功能—— 开启多个定时任务. 当开启另一个定时任务的时候,如果即将开启的这个定时任务的时间段与已经开启了的定时任务的时间段有交 ...

  5. https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

    https://sourceware.org/gdb/onlinedocs/gdb/Forks.html Next: Checkpoint/Restart, Previous: Threads, Up ...

  6. HDU 5072 Coprime 同色三角形问题

    好吧,我承认就算当时再给我五个小时我也做不出来. 首先解释同色三角形问题: 给出n(n >= 3)个点,这些点中的一些被涂上了红色,剩下的被涂上了黑色.然后将这些点两两相连.于是每三个点都会组成 ...

  7. hdu5389 Zero Escape

    Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...

  8. 【u210】kfc

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 最近Kfc新开了个KFC,该KFC提供N种食物,分别用1-N给这些食物编号,食物的价格与其编号有关,满 ...

  9. html常用样式margin、border怎么使用

    html常用样式margin.border怎么使用 一.总结 一句话总结:1.margin:auto配合width才能居中:2.border的三个属性依次是边框宽度,边框样式,边框颜色 1.html中 ...

  10. 【u222】选课

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 黄黄游历完学校,就开始要选课上了. 黄黄同学所在的学校有一个奇怪的上课系统,有N种课可以选择,每种课可 ...