Linux网络服务器配置——认证网站某目录的方法

用户账号保存到认证用户文件中。用户账号也可以保存到MySQL的表中。试参照/etc/httpd/conf.d/auth_mysql.conf第8-38行,做实验:

1、在文档根目录下创建lab目录,在lab下创建主页,内容自定。(5分)

2、以MySQL的root用户,创建数据库auth,在该库中创建表users。(10分)

3、把数据库auth中表users授权给用户lili,权限select,insert,update,delete,密码lili123。(10分)

4、以用户lili连接MySQL,在上述表中插入账号:用户luo,密码luo123;用户guo,密码guo123。(10分)

5、在该目录下创建局部配置文件,实现对该目录的访问认证,用户账号保存到数据库auth的表users中。(10分)

6、在Windows的浏览器中测试。(5分)

写出实验的步骤和结果。


实验过程

1、  [root@localhost html]#mkdirlab  //在文档根目录下创建lab目录

[root@localhost html]# ls

     Lab

 [root@localhost  html]# cd lab

[root@localhost html]# cat >index.html

<h1>

这是期中考试!

</h1>

//在lab目录创建index.html主页,并写入内容

[root@localhost html]#ls

index.html

 

2、  (1)查看本机是否安装mysql,

[root@localhost  lab]#service mysql start

[root@localhost  lab]#chkconfig -–list mysql

(2)以root用户身份登录本机的Mysql服务器

   [root@localhost  lab]#mysql -u root -p
创建数据库auth,在该库中创建表user

mysql>createdatabase auth;

mysql>create table users(user_namechar(30) not null,user_passwd char(30) not           null,primary key (user_name));

QueryOK,0 row affected (0.04 sec)

mysql>show tables;

+----------------+

| Tables_in_auth|

+----------------+

| users          |

+----------------+


3、mysql>grantselect,insert,update,delete on auth.users to lili@localhostidentified by ‘lili123′;

QueryOK,0 row affected (0.04 sec)


4、首先退出mysql的root登录,再以lili身份登录

mysql>exit;

Bye

[root@localhost lab]

Welcometo the MySQL monitor.  Commands end mysql –u lili –plili123with ; or \g.

YourMySQL connection id is 6 to server version: 3.23.54

Type'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>insert intoauth.users(user_name,user_passwd) values ('luo', encrypt('luo123'));

mysql>insert intoauth.users(user_name,user_passwd) values ('guo', encrypt('guo123'));

QueryOK, 1 row affected (0.00 sec)

mysql> select * from auth.users;

+-----------+---------------+

|user_name | user_passwd   |

+-----------+---------------+

|luo        | SKw8j5Zjkl.Bs  |

|guo        | kTX5u5nMJpb/w  |

+-----------+---------------+

    2 rows in set(0.10 sec)






 

5、 [root@localhost lab]# vi/etc/httpd/conf.d/user_auth.conf

    <Directory"/var/www/html/lab">

    Options Indexes

AllowOverride AuthConfig

Order allow,deny

Allow from all

</Directory>

在lab目录下创建局部配置文件

[root@localhost root]# cd /var/www/html/lab

[root@localhost lab]# vi .htaccess

AuthType Basic

AuthName "please inputname&passwd"

AuthUserFile"/var/www/html/lab/.htpasswd"

Require user guangji

[root@localhost lab]# htpasswd -c /var/www/html/lab/.htpasswd guangji

New password:

Re-type new password:

Adding password for user guangji

[root@localhost lab]# apachectl restart


6、在Windows系统下的浏览器地址栏打:http://192.168.78.112/lab

   出现需要身份验证的对话框,输入用户账号和密码,查看lab目录的主页




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

港湾之梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值