cd /mydata/ mkdir nginx1.先随便启动一个nginx实例,只是为了复制出配置
docker run --name nginx -p 80:80 -d nginx:1.102.将容器期内的配置文件拷贝到当前目录( 别忘了后面的 . )
docker container cp nginx:etc/nginx .3.把这个conf移动到/mydata/nginx下
cd ../ # 返回上一级目录 /mydata mv nginx conf # 修改文件名称 mkdir nginx # 再新建一个nginx文件夹 mv conf nginx/ # 将conf文件夹移动到nginx文件夹下5.停止原nginx容器,并删除
docker stop nginx docker rm nginx6.创建新的nginx
创建之前确保nginx文件夹结构如下
[root@localhost nginx]# pwd /mydata/nginx [root@localhost nginx]# ls conf
安装容器
docker run --name nginx -p 80:80 -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/logs:/var/log/nginx -v /mydata/nginx/conf:/etc/nginx -d nginx:1.10
再次检查nginx目录
[root@localhost nginx]# ls conf html logs7、访问nginx欢迎页
此时没有任何页面,会出现403
http://ip:80 http://ip # 默认就是80端口8、可以创建一个简单的页面,验证nginx服务
在html文件夹下创建一个index.html文件,并写入简单的内容仅用于验证。
[root@localhost nginx]# ls conf html logs [root@localhost nginx]# cd html [root@localhost html]# ls [root@localhost html]# vi index.html
index.html 内容
Hello Nginx 2022
重新访问http://ip:80, 就可以看到内容了
nginx基本环境至此搭建完毕。
nginx部署静态资源,可以查看后续文章。



