云计算、AI、云原生、大数据等一站式技术学习平台

网站首页 > 教程文章 正文

Basic认证登录设定

jxf315 2024-12-06 15:53:27 教程文章 48 ℃

1.本文以【[/var/www/html/auth-basic】目录下内容为认证对象。

# vim /etc/httpd/conf.d/auth_basic.conf
添加下列内容:
AuthType Basic                         →认证类型
AuthName "Basic Authentication"        →认证名(认证画面显示的信息)
AuthUserFile /etc/httpd/conf/.htpasswd  →指定用户认证的密码文件
require valid-user                      →指定允许访问的的用户(valid-user指允许,密码文件中包含的所有用户访问)

2.创建用户及密码,这里用户名为【awspack】。

# htpasswd -c /etc/httpd/conf/.htpasswd awspack  →-c是作成新的文件,第一次时选项加"c",以后都不加
New password:          →输入密码
Re-type new password:  →再次输入密码

3.创建网站的目录,添加测试文件。

# mkdir /var/www/html/auth-basic
# vim /var/www/html/auth-basic/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
AWSPACK Test Page for Basic Auth
</div>
</body>
</html>

4.重启Apache。

# /etc/init.d/httpd restart

5.打开浏览器,访问所创建的测试页面。输入自己创建的用户名和密码。

6.如下图可以正常访问。

Tags:

最近发表
标签列表