nginx的部署
2025年6月29日
使用阿里云部署docker
全部菜单→应用管理→部署docker,部署完成后使用docker -v查看docker是否部署成功
安装nginx 1.27.3
1.docker pull nginx:1.27.3
2.使用命令拉取nginx镜像
3.使用docker images查看镜像是否安装成功
nginx配置文件挂载宿主机
1.docker run -d -p 80:80 --name nginx nginx:1.27.3
首次运行nginx容器以提取nginx配置文件
2.使用docker ps查看容器是否启动成功
3.mkdir -p /opt/dockerLib/nginx/conf
docker cp nginx:/etc/nginx/nginx.conf /opt/dockerLib/nginx/conf/
docker cp nginx:/usr/share/nginx/html /opt/dockerLib/nginx/
docker cp nginx:/etc/nginx/conf.d /opt/dockerLib/nginx/conf.d/
创建本机配置文件夹并将nginx容器内conf以及html文件夹复制到本机中
conf文件夹中的配置文件包含include指令指向目录内所有.conf配置文件
conf.d文件夹用以存储额外配置文件
4.mkdir /opt/dockerLib/nginx/ssl
创建ssl文件夹用以后期存储ssl证书、
5.docker rm nginx -f
配置文件提取完毕后将容器删除,准备正式运行nginx容器
6.docker run -p 80:80 -p 443:443 \
-d --name nginx \
-v /opt/dockerLib/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/dockerLib/nginx/conf.d:/etc/nginx/conf.d \
-v /opt/dockerLib/nginx/ssl:/etc/nginx/ssl \
-v /opt/dockerLib/nginx/html:/usr/share/nginx/html \
nginx:1.27.3
7.正式创建nginx容器
端口映射80,用以http域名访问默认端口
端口映射443,用以https域名访问默认端口
-v用以将容器内配置文件挂载到本机,方便后期修改nginx配置文件
http://xx.xx.xx:xx
访问服务器网址,若能出现nginx欢迎页面则代表容器创建成功