Web服务
.编译安装httpd软件包
1.解压并释放源码包
tar zxf httpd-2.2.9.tar.gz –C /tmp/
cd /tmp/httpd-2.2.9
2.配置编译选项
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
u    --prefix:指定httpd程序将要安装到的系统目录,默认目录为”/usr/local/apache2”
u    --enable-so:使httpd服务能够动态加载模块功能
u    --enable-rewrite:使httpd服务具有rewrite网页地址重写功能(如博客中实现二级域名)
除此之外,还有很多配置选项,可根据需要使用
3.编译
make
4.安装
make install
二.虚拟主机
1.基于域名的虚拟主机
     向域名注册机构申请web站点的域名,www.haha.comwww.hehe.comIP地址为172.16.100.5
搭建DNS,确保能够解析。(使用nslookup工具测试)
准备两个虚拟站点的网页文件
cd /usr/local/apache2/htdocs/
mkdir haha
mkdir hehe
echo “I am haha” >haha/index.html
echo “I am hehe” >hehe/index.html
修改httpd.conf文件,添加虚拟主机配置
vi /usr/local/apache2/conf/httpd.conf
……//前面的内容省略
NameVirtualHost 172.16.100.5
<VirtualHost 172.16.100.5>
      DocumentRoot /usr/local/apache2/htdocs/haha/
      Servername www.haha.com
      ErrorLog logs/www.haha.com.error.log
      Customlog logs/www.haha.com.access.log common
</VirtualHost>
<VirtualHost 172.16.100.5>
      DocumentRoot /usr/local/apache2/htdocs/hehe/
      Servername www.hehe.com
      ErrorLog logs/www.hehe.com.error.log
      Customlog logs/www.hehe.com.access.log common
</VirtualHost>
重新启动httpd服务
在启动httpd服务之前,可先对配置内容进行语法检查
[root@localhost conf]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@localhost conf]# /usr/local/apache2/bin/httpd -t
Syntax OK
 
/usr/local/apache2/bin/apachectl start
在客户机浏览器中访问虚拟web站点
2.基于端口的虚拟主机(不需要NameVirtualHost配置行)
vi /usr/local/apache2/conf/httpd.conf
……//前面的内容省略
<VirtualHost 172.16.100.5>
      DocumentRoot /usr/local/apache2/htdocs/haha/
      Servername www.haha.com
      ErrorLog logs/www.haha.com.error.log
      Customlog logs/www.haha.com.access.log common
</VirtualHost>
<VirtualHost 172.16.100.10>
      DocumentRoot /usr/local/apache2/htdocs/hehe/
      Servername www.hehe.com
      ErrorLog logs/www.hehe.com.error.log
      Customlog logs/www.hehe.com.access.log common
</VirtualHost>
3.基于IP地址的虚拟主机
……//前面的内容省略
Listen 172.16.100.5:80
Listen 172.16.100.5:8080
<VirtualHost 172.16.100.5:80>
      DocumentRoot /usr/local/apache2/htdocs/haha/
      Servername www.haha.com
      ErrorLog logs/www.haha.com.error.log
      Customlog logs/www.haha.com.access.log common
</VirtualHost>
<VirtualHost 172.16.100.10:8080>
      DocumentRoot /usr/local/apache2/htdocs/hehe/
      Servername www.hehe.com
      ErrorLog logs/www.hehe.com.error.log
      Customlog logs/www.hehe.com.access.log common
</VirtualHost>
.建立系统用户的个人主页
1.安装Apache,搭建DNS
2.建立个人页面
mkdir /etc/skel/public_html
adduser haha;passwd haha
adduser hehe;passwd hehe
chmod o+x /home/haha
chmod o+x /home/hehe
su - haha
echo "I am haha" >/home/haha/index.html
su - hehe
echo "I am hehe" >/home/hehe/index.html
3.实现基于域名的虚拟主机功能
vi  /usr/local/apache2/conf/httpd.conf
#Include conf/extra/httpd-vhosts.conf   去掉该行“#
vi  /usr/local/apache2/conf /extra/httpd-vhosts.conf
…..//前面的内容省略
NameVirtualHost 172.16.100.5
<VirtualHost 172.16.100.5>
        ServerName www.haha.com
        DocumentRoot /home/haha/public_html/
</VirtualHost>
<VirtualHost 172.16.100.5>
        ServerName www.hehe.com
        DocumentRoot /home/hehe/public_html/
</VirtualHost>
4.实现ftp对个人主页进行更新
vi  /etc/vsftpd/vsftpd.conf
anonymous_enable=NO   //YES该为NO,禁用匿名
chroot_local_user=YES   //用户禁锢在自己的宿主目录中                         
5.重启httpd服务
6.在客户机浏览器中访问个人主页(两种访问方式)
http://www.haha.com
http://172.16.100.5/~haha