美文网首页
docker | nginx 带账号密码的文件服务器

docker | nginx 带账号密码的文件服务器

作者: 炒面Z | 来源:发表于2020-06-30 10:11 被阅读0次

1. docker下nginx的安装

docker run \
-p 8088:80 \
--name=file-nginx \
-v /opt2/file-nginx/conf.d:/etc/nginx/conf.d \
-v /opt2/file-nginx/web/:/etc/nginx/web/ \
-v /opt2/file-nginx/logs:/var/log/nginx/ \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-d nginx

2.nginx配置账号密码

需要进入docker的nginx容器内部,目前系统为ubuntu

apt-get update
#安装apache2-utils
apt-get install apache2-utils
#创建用户名
htpasswd -c /etc/nginx/web/passwd.db 用户名
#输入密码(自动弹出)
New password:
Re-type new password:
#查看用户和密码
cat /etc/nginx/web/passwd.db
#退出
exit

3.nginx配置文件

在宿主机 /opt2/file-nginx/conf.d 目录下配置 default.conf

server {
    listen 80;   
    server_name localhost;
    charset utf-8;
    root /etc/nginx/web;
    client_max_body_size 1G;

    location / {  
        auth_basic "Please input password"; #这里是验证时的提示信息
        auth_basic_user_file /etc/nginx/web/passwd.db;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        root   /etc/nginx/web;
    }
}

4.测试

访问 http://ip:port ,首先弹出账号密码输入框,账号密码输入成功后进入文件浏览页面

image.png

相关文章

网友评论

      本文标题:docker | nginx 带账号密码的文件服务器

      本文链接:https://www.haomeiwen.com/subject/ihptqktx.html