Ubuntu Linux下Apache基於網域名稱的虛擬機器主機配置

來源:互聯網
上載者:User

比如有兩個網域名稱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就不能正確解析
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.