Linux Nginx配置文件下载并添加验证(用户名:密码)增强安全

//系统
# 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

//使用浏览器访问则需要验证用户和密码

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章