Nginx配置Basic Auth登录认证的实现方法
有时候我们通过nginx搭建了一台文件服务器,一般来讲是公开的,但我们又希望该服务器不让他人看到,有人可能会搭建一个登录系统,但是太麻烦,也没太大必要,比较简单的做法是配置BasicAuth登录认证
1.确定你安装了httpd-tools
yuminstallhttpd-tools-y
2.创建授权用户和密码
htpasswd-c-d/usr/local/openresty/nginx/conf/pass_filemagina
这个配置文件存放路径可以随意指定,这里我指定的是nginx配置文件目录,其中magina是指允许登录的用户名,这个可以自定义
3.配置Nginx
大致配置如下:
server{ listen80; server_nameres.yinnote.com; auth_basic"登录认证"; auth_basic_user_file/usr/local/openresty/nginx/conf/pass_file; autoindexon; autoindex_exact_sizeon; autoindex_localtimeon; root/mnt/html/resource; indexindex.htmlindex.php; }
其中auth_basic和auth_basic_user_file是认证的配置,注意密码文件的路径一定是上面生成的
4.使用
#浏览器中使用 直接在浏览器中输入地址,会弹出用户密码输入框,输入即可访问 #使用wget wget--http-user=magina--http-passwd=123456http://res.yinnote.com/xxx.zip #使用curl curl-umagina:123456-Ohttp://res.yinnote.com/xxx.zip
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。