[1] 环境基于 Ubuntu 9.10, Apache 2.2.12
[2] 整个配置过程建立两个虚拟主机,vh001和vh002
[3] 参考自
$ cat /etc/apache2/sites-available/defaultNameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName vh001
ServerAdmin vh001_mail@example.com
DocumentRoot /home/vh001_home/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/vh001_home/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/vh001_home/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/vh001_home/log/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
|
$ cat /etc/apache2/sites-available/vh002<VirtualHost 127.0.0.1>
ServerName vh002
ServerAdmin vh002_mail@example.com
DocumentRoot /home/vh002_home/
ErrorLog /home/vh002_home/log/error.log
CustomLog /home/vh002_home/log/access.log common
</VirtualHost>
|
$ sudo a2ensite vh002 //建立vh002配置文件到/etc/apache2/sites-enabled的符号链接$ sudo service apache2 restart //重启使配置生效$ cat /etc/hosts | grep -E 'vh001|vh002' //添加hosts记录使本机能够通过虚拟主机名访问127.0.0.1 vh001 127.0.0.1 vh002
|
附:初始配置下的/etc/apache2/sites-available/default<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
|
阅读(349) | 评论(0) | 转发(0) |