本文共 2009 字,大约阅读时间需要 6 分钟。
输入网址后不会直接显示网站,而是提示要求你输入密码才能访问;
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/wwwroot/szl.com" ServerName szl.com ServerAlias www.szl.com ; //指定认证的目录 AllowOverride AuthConfig //这个相当于打开认证的开关 AuthName "szl.com user auth" //自定义认证的名字,作用不大 AuthType Basic //认证的类型,一般为Basic AuthUserFile /data/.htpasswd //指定密码文件所在位置 require valid-user //指定需要认证的用户为全部可用用户 ErrorLog "logs/szl.com-error_log" CustomLog "logs/szl.com-access_log" common
创建密码文件与用户名admin
/usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd admin
/usr/local/apache2.4/bin/apachectl -t/usr/local/apache2.4/bin/apachectl graceful
需要输入账号密码就提示代码401正常为代码200
curl -x127.0.0.1:80 szl.com[root@shu-test ~]# curl -x127.0.0.1:80 szl.com401 Unauthorized Unauthorized
This server could not verify that youare authorized to access the documentrequested. Either you supplied the wrongcredentials (e.g., bad password), or yourbrowser doesn't understand how to supplythe credentials required.
[root@shu-test ~]#
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/wwwroot/szl.com" ServerName szl.com ServerAlias www.szl.com# ; ErrorLog "logs/szl.com-error_log" CustomLog "logs/szl.com-access_log" commonAllowOverride AuthConfig AuthName "szl.com user auth" AuthType Basic AuthUserFile /data/.htpasswd require valid-user #
vim /data/wwwroot/szl.com/admin.php
[root@shu-test ~]# cat /data/wwwroot/szl.com/admin.php [root@shu-test ~]#
测试admin.php
需要输入密码测试szl.com,不需要账号密码;转载于:https://blog.51cto.com/shuzonglu/2082186