ubuntu下和windows下配置apache虚拟主机
2012-09-05 09:45:09 来源:WEB开发网 在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 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"
更多精彩
赞助商链接