多个Apache虚拟主机站点的配置方法 - Apache - 服务器之家

服务器之家

专注于服务器技术!
当前位置:首页 > Web服务器 > Apache

多个Apache虚拟主机站点的配置方法

发布时间:2014-04-11 来源:服务器之家

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

    ServerName www.a.com
    ServerName www.b.com
    DocumentRoot "/usr/local/apache/www1"
    Alias /cs "/usr/local/apache/htdocs/phpmyadmin/"
  
    allow from all
  
    DirectoryIndex index.php


    ServerName www.c.com
    DocumentRoot "/usr/local/apache/htdocs"
  
    allow from all
  
    DirectoryIndex index.html index.php
  #Alias /cs "/usr/local/apache/htdocs/phpmyadmin/"这个表示建立虚拟目录为cs,指向地点为phpmyadmin目录   完整配置实例一:  
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    allow from all
   
    DirectoryIndex index.php index.html
          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
#CustomLog "|/usr/local/cronolog/sbin/cronolog /www/www.a.com/logs/access_log.%Y%m%d" combined  #这句是表示按日期写日志到目录文件里面 cronolog下载地址: [url]http://cronolog.org/download/cronolog-1.6.2.tar.gz[/url]   配置详细实例二:
  
        Options FollowSymLinks
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
  

        DirectoryIndex index.php index.html

        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
  多虚拟主机配置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