比如有兩個網域名稱www.linuxidc 和www.linuxidc.net兩個網域名稱要做解析
在/etc/apache2/sites-available 目錄下建立a和b兩個檔案,這裡只是為了使用的方便,你仔細觀察可以看出在sites-enabled檔案下也會有相關的檔案串連(只是一個軟串連)到sites-available 檔案下相應的檔案上
為了方便管理,這裡做的都使用一個名稱也容易記憶。
編輯相應檔案內容如下
NameVirtualHost www.linuxidc
<VirtualHost www.linuxidc>
ServerName www.linuxidc
ServerAlias linuxidc *.linuxidc
ServerAdmin webmaster@linuxidc
DocumentRoot /var/www/a/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/a />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2s 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 /var/log/apache2/a.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/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>
檔案b裡的內容基本和a是一樣的,只需要所少數幾處改一下
執行a2ensite a a2ensite b 命令使虛擬機器主機生效
重啟apache
Java代碼
/etc/init.d/apache2 restart
或者重新載入apache2
Java代碼
/etc/init.d/apache2 reload
修改hosts檔案
Java代碼
vi /etc/hosts
插入下面兩行
127.0.0.1 www.linuxidc
127.0.0.1 www.linuxidc.net
現在訪問兩個網域名稱,會發現解析到了不同的目錄
如果哪個虛擬機器主機不想使用只需要執行命令
Java代碼
a2dissite b
這樣再訪問www.linuxidc.net就不能正確解析