标签:容器 nginx 部署 Nginx usr conf Docker local docker
docker 安装nginx
1.下载nginx镜像
docker pull nginx
2.创建nginx挂载目录
mkdir -p /usr/local/nginx/{conf,html,log,ssl}
3.启动nginx容器,用于copy一些文件放在步骤2的目录下
docker run --name nginx -p 80:80 -d nginx
4.将nginx容器下文件,copy到步骤2的目录下
docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/
docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
docker cp nginx:/usr/share/nginx/html/index.html /usr/local/nginx/html/index.html
5.根据业务修改宿主机目录中的nginx.conf文件、并并删除容器、重启容器
配置项https
配置http转发
6.重启容器
#删除容器
docker rm -f nginx
#启动容器并挂载目录
docker run \
-p 80:80 \
-p 443:443 \
--name nginx \
--restart=always \
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/nginx/conf/cert:/etc/nginx/cert \
-v /usr/local/nginx/ssl:/etc/nginx/ssl/ \
-v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/local/nginx/log:/var/log/nginx \
-v /usr/local/nginx/html:/usr/share/nginx/html \
-d nginx
7.注意事项
defaul.conf文件中,出现的绝对路径都是容器内的路径,而不是宿主机的,比如说配置ssl时:
ssl_certificate /etc/nginx/ssl/telami.cn.pem; #此处不是宿主机目录,而是容器内的路径
ssl_certificate_key /etc/nginx/ssl/telami.cn.key; #此处不是宿主机目录,而是容器内的路径
8.查找安装路径 nginx
whereis nginx
9.查找nginx配置项所在位置
sudo find / -name nginx.conf
10.不重启docker更新nginx配置文件
查看容器
docker ps -a
//测试nginx配置是否正确
docker exec 容器id nginx -t
//重新加载nginx配置
docker exec 容器id nginx -s reload
原文连接:https://www.cnblogs.com/pudefu/p/16887021.html
标签:容器,
nginx,
部署,
Nginx,
usr,
conf,
Docker,
local,
docker
From: https://www.cnblogs.com/huangkai00000/p/17600577.html