为用户创建自己家目录的主页:
1,新增用户wendy
#useradd wendy
2,在wendy家目录下创建public_html目录,并在其目录下创建主页index.html
#su - wendy
#mkdir public_html/
#vim index.html
3,编辑主配置文件/etc/httpd/conf/httpd.conf
将 UserDir disable这一行注释掉,
然后去掉UserDir public_html前面的注释符

#chmod u+x /home/wendy
5,在浏览器窗口中输入
http://10.0.2.2/~wendy/ 就可以看到刚才间的主页的内容了
注意:如果selinux开启的话,要改变刚创建目录的标签
chcon -R -t httpd_sys_content_t /home/wendy/public_html/
-rw-rw-r-- wendy wendy root:object_r:httpd_sys_content_t index.html
二
创建虚拟目录
1,首先创建/var/www/frum/,并在该目录下新建主页文件index.html
#cd /var/www/frum/
#vim index.html
2,编辑主配置文件/etc/httpd/conf/httpd.conf
#vim /etc/httpd/conf/httpd.conf
与其它目录一样设定虚拟目录的所有指令可以放到,<Directory>容器中,在主配置文件中加上以下行,就可以创建一个简单的虚拟目录了
Alias /frum/ "/var/www/frum/"
<Directory "/var/www/frum/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
3,重新启动服务
#service httpd restart
在浏览器中输入
http://10.0.2.2/frum/就可以看到虚拟目录中的内容了
注:这里一定不能忘掉frum后面的/不然的话会出错
三
创建基于用户的认证
这里为了方便我们直接以上面做的试验为基础
1,编辑主配置文件将
#vim /etc/httpd/conf/httpd.conf
Alias /frum/ "/var/www/frum/"
<Directory "/var/www/frum/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>中的AllowOverride None改为AllowOverride AuthConfig然后保存退出
2,在/var/www/frum/目录中创建.htaccess文件
#/var/www/frum/.htaccess在文件中加上以下几行
AuthName "this is frum's home" //这里面的内容可以随意更改
AuthType basic
AuthUserFile /etc/httpd/conf/.htpasswd
Require user bob //指定bob用户可以访问
保存退出
3,为bob用户创建访问密码
[root@station135 frum]# htpasswd -cm /etc/httpd/conf/.htpasswd bob
New password:
Re-type new password:
Adding password for user bob

四
建立基于主机名的虚拟主机
本机的主机名是www135.example.com和station135.example.com
在进行实验之前首先确保ping www135.example.com 和ping station135.example.com 能够通,可以在/etc/hosts中做相应的设置。
1,编辑主配置文件
将DocumentRoot "/var/www/html"注释掉
去掉NameVirtualHost *:80前的注释

为了记录登录信息在这里加入了日志记录
2,重新启动服务

转载于:https://blog.51cto.com/yangzorder/280698