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

相关推荐
wdfk_prog13 小时前
[Linux]学习笔记系列 -- lib/sort.c 通用的排序库(Generic Sorting Library) 为内核提供标准的、高效的排序功能
linux·运维·c语言·笔记·stm32·学习·bug
jump_jump13 小时前
前端部署工具 PinMe
运维·前端·开源
それども14 小时前
本地怎么远程调试服务器
运维·服务器
斯普信专业组16 小时前
Filebeat写ElasticSearch故障排查思路(上)
运维·elasticsearch·中间件·filebeat
Lin_Aries_042116 小时前
通过配置 GitLab 自动触发项目自动化构建与部署
运维·docker·容器·自动化·云计算·gitlab
zybsjn16 小时前
【实战】理解服务器流量监控中的“上行”和“下行”
运维·服务器
尘埃不入你眼眸17 小时前
Docker操作命令
运维·docker·容器
龙茶清欢17 小时前
2、Nginx 与 Spring Cloud Gateway 详细对比:定位、场景与分工
java·运维·spring boot·nginx·spring cloud·gateway
云动雨颤17 小时前
Linux运维必备:3个内存问题排查命令
linux·运维
失因17 小时前
Nginx 特性、配置与实战部署
运维·数据库·nginx