在apache2的sites-available目录下放置多个站点
我用的ubuntu。
在sites-available目录下放置了两个站点:example.net example.org
<VirtualHost *:80>
ServerAdmin webmaster@example.net
ServerName example.net
ServerAlias www.example.net
DocumentRoot /var/www/example.net/public_html/
ErrorLog /var/www/example.net/logs/error.log
CustomLog /var/www/example.net/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /var/www/example.org/public_html/
ErrorLog /var/www/example.org/logs/error.log
CustomLog /var/www/example.org/logs/access.log combined
</VirtualHost>
#Configure VirtualHost, Based IP
#基于IP,一个IP一个站点,如需指定日志,参照xxxx.net
<VirtualHost 192.168.1.1:80>
DocumentRoot /var/www/abc/
ServerName www.abc.cn
</VirtualHost>
<VirtualHost 192.168.1.2:80>
ServerAdmin webmaster@localhost
ServerName xxxx.net
DocumentRoot /var/www/xxxx/
CustomLog /var/log/apache2/xxxx-access.log
ErrorLog /var/log/apache2/xxxx-error.log
</VirtualHost>
#Configure NameVirtualHost, Based Name, 2013.10.5
#基于名称,同个IP多个站点
NameVirtualHost 192.168.1.3:80
<VirtualHost 192.168.1.3:80>
DocumentRoot /var/www/web1/
ServerName web1.abc.org
</VirtualHost>
<VirtualHost 192.168.1.3:80>
DocumentRoot /var/www/web2/
ServerName web2.abc.org
</VirtualHost>
<VirtualHost 192.168.1.3:80>
DocumentRoot /var/www/bbs/
ServerName bbs.com
</VirtualHost>
sudo cp /etc/apache2/sites-enabled/default /etc/apache2/sites-enabled/default.bak;
sudo service apache2 restart;