在ubuntu下配置虚拟主机:
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前的#去掉 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 command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> ServerAdmin webmaster@dummy-host.test DocumentRoot "D:/WorkSpace/ApacheWebs2" ServerName www.test1.com ServerAlias www.dummy-host.test ErrorLog "logs/dummy-host.test-error.log" CustomLog "logs/dummy-host.test-access.log" common </VirtualHost> <Directory "D:/WorkSpace/ApacheWebs2"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.test DocumentRoot "D:/WorkSpace/ApacheWebs3" ServerName www.test2.com ErrorLog "logs/dummy-host2.test-error.log" CustomLog "logs/dummy-host2.test-access.log" common </VirtualHost> <Directory "D:/WorkSpace/ApacheWebs3"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> 上面的配置文件中设置了两个虚拟主机,对应的服务器名及web站点目录名分别为: Servername: www.test1.com -> D:/WorkSpace/ApacheWebs2Servername:www.test2.com -> D:/WorkSpace/ApacheWebs3
如果不希望站点显示目录的话,可以将[Directory]中options的indexes前加上[-],即:
<Directory "D:/WorkSpace/ApacheWebs3"> Options -Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> 以上配置结束后,保存文件. 并重新启动Apache服务即可. 如果是本地调试的话,还需要修改一下Hosts文件,否则的话。。。,你自己试试就知道了 打开c:\windows\system2\drivers\etc\Hosts文件 加入以下代码: 127.0.0.1 www.test1.com 127.0.0.1 www.test2.com 打开IE,分别输入: http://www.test1.com http://www.test2.com 就可以看到效果了。 (责任编辑:IT) |