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. 访问结果

相关推荐
Elastic 中国社区官方博客11 分钟前
Elastic-caveman : 在不损失 Elastic 最佳效果的情况下,将 AI 响应 tokens 减少64%
大数据·运维·数据库·人工智能·elasticsearch·搜索引擎·全文检索
jsons11 小时前
给每台虚拟机设置独立控制台密码
linux·运维·服务器
云栖梦泽2 小时前
Linux内核与驱动:14.SPI子系统
linux·运维·服务器·c++
福大大架构师每日一题2 小时前
openclaw v2026.4.24 发布:Google Meet 深度集成、DeepSeek V4 上线、浏览器自动化与插件架构全面升级
运维·架构·自动化·openclaw
yipiantian3 小时前
在Claude项目中实现跨目录访问Skills
linux·运维·服务器
Agent产品评测局3 小时前
生产排期与MES/ERP系统打通,实操方法详解 —— 2026企业级智能体自动化选型与实战指南
java·运维·人工智能·ai·chatgpt·自动化
cen__y3 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言
MT5开发3 小时前
Linux安装MariaDB
linux·运维·mariadb
你好,帅哥4 小时前
openssl ,msys2 ,交叉编译
linux·运维·服务器
计算机安禾4 小时前
【Linux从入门到精通】第36篇:DNS服务探秘——自己搭建一个内网DNS
linux·运维·servlet