解释一下标题
如果我们想修改nginx的配置,想更改nginx中的资源文件怎么办?就是将容器中的目录和本机目录做映射,以达到修改本机目录文件就影响到容器中的文件。
一、本机创建文件夹
- 大致结构
/home
|---panwei
|----nginx
|----conf.d
|----html
二、 在conf.d文件夹下新建default.conf文件
server {
listen 80;
server_name localhost;
# 原来的配置,匹配根路径
#location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
#}
# 更该配置,匹配/路径,修改index.html的名字,用于区分该配置文件替换了容器中的配置文件
location / {
root /usr/share/nginx/html;
index index-test.html index.htm;
}
}
三、在html中编写index-test.html,用以判断文件夹映射成功
<html>
<body>
<h1>this is homePage1</h2>
</body>
</html>
四、启动nginx(8080),映射路径
docker run -d -p 8080:80 -v /home/panwei/nginx/conf.d:/etc/nginx/conf.d -v /home/panwei/nginx/html:/usr/share/nginx/html nginx
-v,-v的意思就是冒号前面代表本机路径,冒号后面代表容器内的路径,两个路径进行了映射,本机路径中的文件会覆盖容器内的文件。
nginx容器内的一些文件位置:
日志位置:/var/log/nginx/
配置文件位置:/etc/nginx/
项目位置:/usr/share/nginx/html
- 效果: