Nginx配置Basic Auth登录认证的实现方法

这篇文章主要介绍了Nginx配置Basic Auth登录认证的实现方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
有时候我们通过nginx搭建了一台文件服务器, 一般来讲是公开的, 但我们又希望该服务器不让他人看到, 有人可能会搭建一个登录系统, 但是太麻烦, 也没太大必要, 比较简单的做法是配置Basic Auth登录认证

  1. 确定你安装了httpd-tools

yum install httpd-tools -y
2. 创建授权用户和密码

htpasswd -c -d /usr/local/openresty/nginx/conf/pass_file magina
这个配置文件存放路径可以随意指定, 这里我指定的是nginx配置文件目录, 其中magina是指允许登录的用户名, 这个可以自定义

  1. 配置Nginx

大致配置如下:

server { listen 80; server_name res.yinnote.com; auth_basic “登录认证”; auth_basic_user_file /usr/local/openresty/nginx/conf/pass_file; autoindex on; autoindex_exact_size on; autoindex_localtime on; root /mnt/html/resource; index index.html index.php;}
其中 auth_basic 和 auth_basic_user_file 是认证的配置, 注意密码文件的路径一定是上面生成的友情链接检查

  1. 使用

浏览器中使用直接在浏览器中输入地址, 会弹出用户密码输入框, 输入即可访问# 使用 wgetwget --http-user=magina --http-passwd=123456 http://res.yinnote.com/xxx.zip# 使用 curlcurl -u magina:123456 -O http://res.yinnote.com/xxx.zip

猜你喜欢

转载自blog.csdn.net/sakura379/article/details/89839838