WEB 页面认证


1:安装htpasswd工具生成加密文件

安装工具

# yum install httpd-tools

# htpasswd -cm /etc/httpd/passwd/password usera
New password:
Re-type new password:
Adding password for user usera

htpasswd命令选项介绍:
  -c 创建一个加密文件   -n 不更新加密文件,只将apache htpasswd命令加密后的用户名密码显示在屏幕上   -m 默认apache htpassswd命令采用MD5算法对密码进行加密   -d apache htpassswd命令采用CRYPT算法对密码进行加密   -p apache htpassswd命令不对密码进行进行加密,即明文密码   -s apache htpassswd命令采用SHA算法对密码进行加密   -b 在apache htpassswd命令行中一并输入用户名和密码而不是根据提示输入密码   -D 删除指定的用户

2:Apache 配置

<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/xxx.com"
    ServerName xxx.com
    <FilesMatch admin.php>    //admin.php就是单个文件的文件名
        AllowOverride AuthConfig
        AuthName "xxx.com user auth"
        AuthType Basic
        AuthUserFile /etc/httpd/passwd/password
        require valid-user
   ###  Require all granted  // 2.4 注意要注释掉
    </FilesMatch>
</VirtualHost>

说明:
Require valid-user这个选项是所有passwd文件中的用户都能进行认证,
如果不想所有用户指向指定个别用户,可以用命令 require user 用户1 用户2 用户3

 

2:Nginx 配置

location / {
  root /webroot;
  index index.php index.html index.htm;
  } 

  location /bbs {
  alias /webroot/discurz;
  index index.php index.html index.htm;
  include /etc/nginx/conf.d/php;
  auth_basic "Authorized user ? ";
  auth_basic_user_file  /etc/httpd/passwd/password;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM