linux下apache服务器多虚拟主机的配置
我想在服务器的80端口进行配置(当然你也可添加其他的端口)
1:安装apache,这部分我在前面写过,就不重复了
2:我把apache安装在/usr/local/目录下,即apache的安装目录为/usr/local/apache
3:
cd /usr/local/apache/conf
vi httpd.conf
在httpd.conf的文件末尾加上
Include /usr/local/apache/conf/vhost.conf
同时在 /usr/local/apache/conf目录下,vi vhost.conf
内容如下:

NameVirtualHost 192.168.1.231:80
<VirtualHost 192.168.1.231:80>
    ServerName www.a.com
    ServerName www.b.com
    DocumentRoot "/usr/local/apache/www1"
    Alias /cs "/usr/local/apache/htdocs/phpmyadmin/"
   <directory "/usr/local/apache/www1">
    allow from all
   </directory>
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost 192.168.1.231:80>
    ServerName www.c.com
    DocumentRoot "/usr/local/apache/htdocs"
   <directory "/usr/local/apache/htdocs">
    allow from all
   </directory>
    DirectoryIndex index.html index.php
</VirtualHost>
 
#Alias /cs "/usr/local/apache/htdocs/phpmyadmin/"这个表示建立虚拟目录为cs,指向地点为phpmyadmin目录
 
完整配置实例一:
<VirtualHost *:81>
 <Directory /www/www.a.com/www/htdocs>
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    allow from all
 </Directory>
 <IfModule dir_module>
    DirectoryIndex index.php index.html
 </IfModule>
        ServerAdmin swm9988@gmail.com          
        DocumentRoot /www/www.a.com/www/htdocs
        ServerName www.a.com
        ErrorLog /www/www.a.com/logs/error_log
CustomLog "|/usr/local/cronolog/sbin/cronolog /www/www.a.com/logs/access_log.%Y%m%d" combined
</VirtualHost>
#CustomLog "|/usr/local/cronolog/sbin/cronolog /www/www.a.com/logs/access_log.%Y%m%d" combined  #这句是表示按日期写日志到目录文件里面
cronolog下载地址:
 
配置详细实例二:
<VirtualHost *:80>
   <Directory /www/www.test.com/www/htdocs>
        Options FollowSymLinks
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
   </Directory>
<IfModule dir_module>
        DirectoryIndex index.php index.html
</IfModule>
        ServerAdmin swm9988@gmail.com
        DocumentRoot /www/www.test.com/www/htdocs
        ServerName www.test.com
        ErrorDocument 404 /index.php
 ErrorLog /www/www.test.com/logs/error_log
        CustomLog "|/usr/local/cronolog/sbin/cronolog /www/www.test.com/logs/access_log.%Y%m%d" combined
</VirtualHost>
 
多虚拟主机配置80端口在同一文件中的配置前要加
NameVirtualHost *:80
多虚拟主机配置80端口在多配置文件中在httpd.conf最后加
NameVirtualHost *:80
Include /usr/local/apache/conf/Includes/*.conf
再建立Includes文件夹
# mkdir /usr/local/apache/conf/Includes
新建你的*.conf文件,比如www.test.com.conf