docker安装nginx做文件服务器,配置认证

1、创建dockerfile文件:Dockerfile

FROM nginx
COPY /etc/localtime /etc/localtime
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./passwd.db /etc/nginx/passwd.db
EXPOSE 80

2、创建nginx配置文件: nginx.conf

events {}
 
http {
    server {
        listen 80;
 
        location / {
            auth_basic "Please input password"; #这里是验证时的提示信息 
              auth_basic_user_file /etc/nginx/passwd.db;
            root /usr/share/nginx/html; # 文件存储目录
            autoindex on; # 开启索引功能,展示目录列表
            autoindex_exact_size off; # 显示文件大小
            autoindex_localtime on; # 显示文件时间
        }
    }
}

3、创建账号密码文件

#安装软件
yum install -y httpd-tools 
#创建nginx用户
htpasswd -c ./passwd.db nginx
#输入密码(自动弹出)
New password: 
Re-type new password:

4、启动容器

docker run -d -p 8888:80 --name nginx-server -v   /data/application:/usr/share/nginx/html nginx-file-server:latest
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容