修改或者创建conf文件

vim /etc/httpd/conf.d/auth_basic.conf
</bash>
<code apache>
[root@www ~]# vi /etc/httpd/conf.d/auth_basic.conf
# create new
<Directory /var/www/html/auth-basic>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/httpd/conf/.htpasswd
    require valid-user
</Directory>
# add a user : create a new file with "-c" ( add the "-c" option only for the initial registration )
[root@www ~]# htpasswd -c /etc/httpd/conf/.htpasswd cent 
New password: # set password
Re-type new password: # confirm
Adding password for user cent
[root@www ~]# systemctl restart httpd
[root@www ~]# mkdir /var/www/html/auth-basic 
[root@www ~]# vi /var/www/html/auth-basic/index.html
# create a test page
 <html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Auth
</div>
</body>
</html>

打开浏览器试试

评论

请输入您的评论. 可以使用维基语法: