VMware下Linux虚拟机实现浏览器登陆认证

字体大小: 中小 标准 ->行高大小: 标准

这里指的是类似登陆数据库时http://www.linuxidc.com时出来的那个验证框,在虚拟机下用Linux实现

[root@linuxidc ~]# mkdir /var/www/html/protect

[root@linuxidc ~]#echo "ceshi" /var/www/html/protect/index.html

[root@linuxidc ~]# mkdir /var/www/apache.passwd
编辑httpd.conf添加以下的一段话

[root@linuxidc ~]# vi /etc/httpd/conf/httpd.conf

确保有这段话

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>
然后找个合适的地方添加下边这段话

<Directory "/var/www/html/protect">
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>


接下来

[root@linuxidc ~]# vi /var/www/html/protect/.htaccess
AuthName       "protect wanyan by .htaccess"
Authtype        Basic
AuthUserFile    /var/www/apache.passwd
require         valid-user
然后添加登陆的用户名和密码

[root@linuxidc ~]# htpasswd /var/www/apache.passwd username
New password:
Re-type new password:
Adding password for user username


接着重启httpd

[root@linuxidc ~]#apachectl restart或者[root@linuxidc ~]#/etc/init.d/httpd restart

最后在浏览器输入http://ip/protect即可测试验证(ip为你的Linux主机ip)

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/61847.html