当前位置:   首页安装配置

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

发布日期:2021-11-13 16:02 | 文章来源:站长之家

有时候我们通过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是指允许登录的用户名, 这个可以自定义

3. 配置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 是认证的配置, 注意密码文件的路径一定是上面生成的

4. 使用

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部