Nginx & Apache_网站用户认证

介绍

Nginx Apache 思路一样 百度找对应Demo添加即可

认证也就是访问网址的时候 需要填写一个账户密码 这个就是Apache Nginx  htpasswd 命令生成的认证账户

  • 做文件服务器的使用这个认证方式比较多
  • 本地没有的自行百度安装htpasswd
  • 这东西会验证所有的的站点资源 只要访问就会验证用户信息


htpasswd 是开源 http 服务器 apache httpd 的一个命令工具,用于生成 http 基本认证的密码文件。

第一步:先创建账号文件信息 (密码默认md5)

// 创建账号文件 并添加第一个账号
htpasswd -bc .passwd test 123456

test:用户名
123456:密码

第二步:修改Apache Nginx站点配置

<VirtualHost *:80>
   DocumentRoot C:Resfiles
   ServerName www.file.com
</VirtualHost> 

<Directory "C:Resfiles">
    #开启文件目录功能
    Options Indexes FollowSymLinks
    #设置展示文件编码
    IndexOptions Charset=UTF-8
    #必须
    AllowOverride authconfig
    
    DirectoryIndex index.html index.php
</Directory>

第三步:站点根目录创建.htaccess

authname "input your userinfo 这里随便写名字"
authtype basic
authuserfile C:RessoftWarephpstudyPHPTutorialApachein.passwd
require valid-user
追加账号
htpasswd -b .passwd test2 123456

 

可参考的文章

注重细节——关注底层——注重细节——关注底层——注重细节——关注底层——注重细节——关注底层——注重细节——关注底层
原文地址:https://www.cnblogs.com/PJG20/p/13087811.html