假定现在有 2 个域名,分别是 xxx.com 与 yyy.com,对应本地目录是 /var/www/xxx/ 与 /var/www/yyy/。

接下来我们创建 2 个有效站点的配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ vi /etc/apache2/sites-available/xxx.com
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName xxx.com
ServerAlias www.xxx.com
CustomLog /var/log/apache2/xxx.com-access.log combined
DocumentRoot /var/www/xxx/

<Directory /var/www/xxx/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>

$ vi /etc/apache2/sites-available/yyy.com
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName yyy.com
ServerAlias www.yyy.com
CustomLog /var/log/apache2/yyy.com-access.log combined
DocumentRoot /var/www/yyy/

<Directory /var/www/yyy/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>

最后创建 2 个快捷方式并重启 apache。

1
2
3
$ ln -s /etc/apache2/sites-available/xxx.com /etc/apache2/sites-enabled/xxx.com
$ ln -s /etc/apache2/sites-available/yyy.com /etc/apache2/sites-enabled/yyy.com
$ /etc/init.d/apache2 force-reload