//系統
# lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
# uname -r
4.19.97-v7l+
//Nginx版本
# nginx -v
nginx version: nginx/1.14.2
//需要安裝apache
# apt-get -y install httpd
//創建admin用戶,並生成加密密碼文件
# /usr/local/apache/bin/htpasswd -c /etc/nginx/conf.d/.htpasswd admin
//Enter 後2次輸入需要設置的密碼
//在nginx 配置文件server配置中增加如下配置
auth_basic "Please conduct security verification!";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
//配置示例
server {
listen 80;
server_name _;
auth_basic "Please conduct security verification!";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
location / {
root html/software;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
//使用 wget 下載,示例
# wget "http://localhost:80/test.zip" --http-user=admin --http-passwd=yourpasswd
//使用瀏覽器訪問則需要驗證用戶和密碼