Day-07 修改 Nginx 配置文件-CSDN博客
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
至此 简单的 Docker 安装 Nginx并启动算是成功了!
ps:
如何修改 Nginx的配置、更改nginx 的资源文件
eg
1、可以将容器中的目录和本机目录做映射。
2、达到修改本机目录文件就影响到容器中的文件。
1.本机创建实例文件夹
新建目录 大致结构如下
/home
|---mutou
|----nginx
|----conf.d
|----html
mkdir mutou
cd mutou/
mkdir nginx
cd nginx/
mkdir conf.d
mkdir html
cd conf.d/
2. 在conf.d文件夹下新建default.conf文件
vi 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;
}
}
ps esc + wq + 回车
3.在html中创建编写 index-test.html 用以判断文件夹映射成功
vi index-test.html
内容如下
<html>
<body>
<h2>it is html1</h2>
</body>
</html>
4. 启动nginx(8080)映射路径
启动代码如下
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. 重启容器
docker restart e25f8d911f44