Nginx配置文件下载
# Nginx配置文件下载
# 关键信息
配置完成后,访问:http://ip:port/down 输入账号密码即可。
我自用的新建 htpasswd 的创建命令:
echo "admin:k5aiMxLyKPL6A" | sudo tee /usr/local/nginx/conf/htpasswd >/dev/null
location /down {
# 需要开放的存放文件的文件夹
alias /opt/nginxdownfiles/;
# 有些后缀的文件nginx会直接打开,但是既然做这个配置肯定是要下载,下面的if就是配置让那些后缀下载而不是打开的
if ($request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt)$) {
add_header Content-Disposition attachment;
add_header Content-Type application/octet-stream;
}
proxy_buffering off; # 禁用缓冲(不加的话大文件上传可能会出问题)
client_max_body_size 2048M; # 限制上传文件大小最大2048MB
sendfile on; # 开启高效文件传输模式
autoindex on; # 开启目录文件列表
autoindex_exact_size off; # 显示出文件的确切大小,单位是bytes
autoindex_localtime on; # 显示的文件时间为文件的服务器时间
charset utf-8,gbk; # 避免中文乱码
# 配置访问认证
auth_basic "Authorized users only";
# 这个 htpasswd 文件需要自己新建,在线生成对应格式的账号密码的网站:https://tool.oschina.net/htpasswd 选择 Crypt(all Unix servers)
# 生成好了粘贴进下面的文件里 例如账号:admin 密码 admin@123 生成之后,并写入文件的命令如下:
# echo "admin:k5aiMxLyKPL6A" | sudo tee /usr/local/nginx/conf/htpasswd >/dev/null
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
编辑 (opens new window)
上次更新: 2023/05/28, 08:23:00