日期:2014-05-16  浏览次数:20950 次

ubuntu下和windows下配置apache虚拟主机

在ubuntu下配置虚拟主机:

1.        以root用户命令行进入/etc/apache2/sites-available/目录。

2.        创建虚拟主机配置文件,以域名命名创建文件,如aaron.com,你需要创建文件aaron,

NameVirtualHost *:9011

<VirtualHost *:9001>

ServerAdmin master@test.com  #邮件地址

ServerName www.aaron.com  #域名

DocumentRoot /var/www/aaron  #虚拟主机目录

<Directory /var/www/aaron>

Options Indexes FollowSymLinks MultiViews

               AllowOverride None#如果配置url重写,则将该行改为AllowOverride All

                Order allow,deny

                allow from all

</Directory>

 ErrorLog/var/log/apache2/www_test_com_error.log

       LogLevel warn

       CustomLog /var/log/apache2/www_test_com_access.log combined

       ServerSignature On

</VirtualHost>

3.        命令行进/etc/apache2/目录

vi posts.conf

增加两行文字,配置相应的监听端口。

NameVirtualHost *:9001

Listen 9001

4.        在/etc/apache2下执行  a2ensite aaron

此命令是在/etc/apache2/sites-enabled目录下建立一个指向/etc/apache2/site-avaiable目录下wwwtest的软连接

执行/etc/init.d/apache2reload 执行配置文件重新载入

不报错说明配置成功



下面说在windows下如何配置apache的虚拟主机:

将Include前的#去掉

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

保存修改后的httpd.conf

4、配置httpd-vhosts.conf

打开httpd-vhosts.conf文件,将该文件内容指定为:

复制代码
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the comma