1.创建个人用户和站点

[root@localhost ~]# useradd baidu

[root@localhost ~]# passwd baidu   

Changing password for user baidu

[root@localhost ~]# su - baidu

[baidu@localhost ~]$ mkdir public_html

[baidu@localhost ~]$ cd public_html/

[baidu@localhost public_html]$ vim index.html

hello baidu~

~

2.配置个人站点的文档

--安装密文访问

[root@localhost ~]# yum install mod_ssl

[root@localhost ~]# service httpd  start

Starting httpd:                                            [  OK  ]

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

134   Listen 80—明文访问

349 <IfModule mod_userdir.c>

--存放发布个人站点的模块

--一般是禁用的

355    #UserDir disable—默认是禁用的

362    # UserDir public_html

364     UserDir public_html—取消禁用,目录要与个人站点的一致

365 </IfModule>

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

[root@localhost ~]# service httpd restart  

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

[root@localhost ~]#

[root@localhost ~]# netstat -tupln |grep http

tcp        0      0 :::80                       :::*                        LISTEN      2272/httpd         

tcp        0      0 :::443                      :::*                        LISTEN      2272/httpd         

[root@localhost ~]#

 

3.权限被拒绝

 
 

22-1

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />

[baidu@localhost ~]$ cd ..

[baidu@localhost home]$ ll

total 12

drwx------ 4 baidu  baidu  4096 Aug 23 23:22 baidu

drwx------ 3 redhat redhat 4096 Aug 12 13:32 redhat

[baidu@localhost home]$ chmod o+rx baidu

[baidu@localhost home]$ pwd

/home

3.访问个人站点

 


22-2 

 

4.去掉~访问个人站点

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

alias /baidu "/home/baidu/public_html"

[root@localhost ~]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

 

 

22-3 

5.baidu用户上实现身份验证,只允许其定义的用户可以访问个人网站

--定义身份验证

--在站点的总目录里

[baidu@localhost public_html]$ pwd

/home/baidu/public_html

[baidu@localhost public_html]$

[baidu@localhost public_html]$ vim .htaccess

authuserfile /home/baidu/public_html/.passwd

authtype basic

authname "please input your name and your password:"

require valid-user

--创建登陆验证用户

[baidu@localhost public_html]$ htpasswd -c .passwd zhangsan

New password:

Re-type new password:

Adding password for user zhangsan

[baidu@localhost public_html]$ htpasswd .passwd lisi   

New password:

Re-type new password:

Adding password for user lisi

[baidu@localhost public_html]$ cat .passwd

zhangsan:cHgZASaOvpzgA

lisi:aCb52rQLOeTJg

[baidu@localhost public_html]$ ~   

 

6.打开目录安全性

--指定目录安全性的目录     

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

[root@localhost ~]#                  

372 <Directory /home/*/public_html>

373    AllowOverride all

374 #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

375 #    <Limit GET POST OPTIONS>

376 #        Order allow,deny

377#         Allow from all

378 #    </Limit>

379 #    <LimitExcept GET POST OPTIONS>

380 #        Order deny,allow

381 #        Deny from all

382 #    </LimitExcept>

383 </Directory>

 

400 AccessFileName .htaccess

 

-- Web保护某些文件

406 <Files ~ "^\.ht">

407     Order allow,deny

408     Deny from all

409 </Files>

 

[root@localhost ~]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

 

 

7.验证身份的用户登陆测试

 


22-4