Day-07 修改 Nginx 配置文件

至此: 简单的 Docker 安装 Nginx并启动算是成功了!

ps:

如何修改 Nginx的配置、更改nginx 的资源文件?

eg:

1、可以将容器中的目录和本机目录做映射。

2、达到修改本机目录文件就影响到容器中的文件。

1.本机创建实例文件夹

新建目录, 大致结构如下:

bash 复制代码
/home
    |---mutou
           |----nginx
                  |----conf.d
                  |----html
bash 复制代码
mkdir mutou

cd mutou/
mkdir nginx

cd nginx/
mkdir conf.d
mkdir html

cd conf.d/

2. 在conf.d文件夹下新建default.conf文件:

bash 复制代码
vi default.conf

内容如下:

bash 复制代码
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;
    }
}

ps: esc + wq + 回车

3.在html中创建编写 index-test.html 用以判断文件夹映射成功:

bash 复制代码
vi index-test.html

内容如下:

html 复制代码
<html>
  <body>
    <h2>it is html1</h2>
  </body>
</html>

4. 启动nginx(8080),映射路径

启动代码如下:

bash 复制代码
docker run -d -p 8080:80 
-v /home/mutou/nginx/conf.d:/etc/nginx/conf.d  
-v /home/mutou/nginx/html:/usr/share/nginx/html 
nginx

5. 重启容器

bash 复制代码
docker restart e25f8d911f44

6. 访问结果

相关推荐
眠りたいです1 天前
Docker核心技术和实现原理第二部分:docker镜像与网络原理
运维·网络·docker·容器
XiaoHu02071 天前
Linux多线程(详细全解)
linux·运维·服务器·开发语言·c++·git
Y淑滢潇潇1 天前
RHCE Day 10 流程控制之条件语句和循环结构
linux·运维·rhce
gaize12131 天前
服务器怎么选择与配置才能满足企业需求?
运维·服务器·架构
GDAL1 天前
NJS 共享字典(ngx.shared)全解析:跨 Worker 进程的数据共享方案
nginx·shared·njs
xifangge20251 天前
PHP 错误日志在哪里看?Apache / Nginx / PHP-FPM 一次讲清
nginx·php·apache
鸠摩智首席音效师1 天前
如何安装和配置 Nginx 反向代理服务器 ?
运维·nginx
Shanxun Liao1 天前
CentOS 7.9 根分区 / 已经 100% 用满隐藏占用解决办法
linux·运维·centos
FOREVER-Q1 天前
Windows 下通过 SSH 替代 Gitee OAuth Token 推送配置指南
运维·服务器
Cyber4K1 天前
【Kubernetes专项】DockerFile、数据持计划、网络模式及资源配额
运维·网络·云原生·容器·kubernetes