Docker 安装 Nginx
安装
docker pull nginx
配置
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/conf/ssl
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
SSL
# HTTPS www.lookeke.cn
server {
#SSL 默认访问端口号为 443
listen 443 ssl;
#请填写绑定证书的域名
server_name www.lookeke.cn;
#请填写证书文件的相对路径或绝对路径
ssl_certificate /home/nginx/conf/ssl/lookeke.cn_nginx/lookeke.cn_bundle.crt;
#请填写私钥文件的相对路径或绝对路径
ssl_certificate_key /home/nginx/conf/ssl/lookeke.cn_nginx/lookeke.cn.key;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
#例如,您的网站主页在 Nginx 服务器的 /etc/www 目录下,则请修改 root 后面的 html 为 /etc/www。
root /home/nginx/html/web;
index index.html index.htm;
}
}
测试
检查配置文件是否有误
nginx -t
重启读取配置
docker restart nginx
运行
--restart:
no
:不自动重启容器,默认值。on-failure[:max-retries]
:只有在容器以非0状态(即失败)退出时才会重启,可指定最大重试次数。always
:不管容器是以什么状态退出,都将尝试重启容器。unless-stopped
:除非手动停止了容器,否则总是尝试自动重启容器。
docker run \
-p 80:80 \
-p 443:443 \
--restart=unless-stopped \
--name nginx \
-v /home/nginx/cache:/var/cache/nginx \
-v /home/nginx/ssl:/etc/nginx/ssl \
-v /home/nginx/conf/:/etc/nginx/conf/ \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest