5. 創(chuàng)建虛擬主機(jī)配置文件
默認(rèn)情況下,apache有一個(gè)默認(rèn)的虛擬主機(jī)文件叫000-default.conf,。我們將會(huì)復(fù)制000-default.conf文件內(nèi)容到我們新的虛擬主機(jī)配置文件中。
- sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.conf
- sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen2.local.conf
確保虛擬主機(jī)配置文件末尾包含.conf擴(kuò)展名。
現(xiàn)在,,修改unximen1.local.conf文件以符合需求。
- sudo vi /etc/apache2/sites-available/unixmen1.local.conf
使相關(guān)的變化直接呈現(xiàn)在unixmen1站點(diǎn)中(譯注:以“#”開頭的注釋行可以忽略,。),。
- <VirtualHost *:80>
- # The ServerName directive sets the request scheme, hostname and port that
- # the server uses to identify itself. This is used when creating
- # redirection URLs. In the context of virtual hosts, the ServerName
- # specifies what hostname must appear in the request's Host: header to
- # match this virtual host. For the default virtual host (this file) this
- # value is not decisive as it is used as a last resort host regardless.
- # However, you must set it for any further virtual host explicitly.
- #ServerName www.example.com
- ServerAdmin [email protected]
- ServerName unixmen1.local
- ServerAlias www.unixmen1.local
- DocumentRoot /var/www/unixmen1.local/public_html
- # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
- # error, crit, alert, emerg.
- # It is also possible to configure the loglevel for particular
- # modules, e.g.
- #LogLevel info ssl:warn
- ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
- # For most configuration files from conf-available/, which are
- # enabled or disabled at a global level, it is possible to
- # include a line for only one particular virtual host. For example the
- # following line enables the CGI configuration for this host only
- # after it has been globally disabled with "a2disconf".
- #Include conf-available/serve-cgi-bin.conf
- </VirtualHost>
同理,修改第二臺(tái)主機(jī)文件,。
- sudo vi /etc/apache2/sites-available/unixmen2.local.conf
使相關(guān)的修改在unixmen2 站點(diǎn)呈現(xiàn)出來,。
- <VirtualHost *:80>
- # The ServerName directive sets the request scheme, hostname and port that
- # the server uses to identify itself. This is used when creating
- # redirection URLs. In the context of virtual hosts, the ServerName
- # specifies what hostname must appear in the request's Host: header to
- # match this virtual host. For the default virtual host (this file) this
- # value is not decisive as it is used as a last resort host regardless.
- # However, you must set it for any further virtual host explicitly.
- #ServerName www.example.com
- ServerAdmin [email protected]
- ServerName unixmen2.local
- ServerAlias www.unixmen2.local
- DocumentRoot /var/www/unixmen2.local/public_html
- # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
- # error, crit, alert, emerg.
- # It is also possible to configure the loglevel for particular
- # modules, e.g.
- #LogLevel info ssl:warn
- ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
- # For most configuration files from conf-available/, which are
- # enabled or disabled at a global level, it is possible to
- # include a line for only one particular virtual host. For example the
- # following line enables the CGI configuration for this host only
- # after it has been globally disabled with "a2disconf".
- #Include conf-available/serve-cgi-bin.conf
- </VirtualHost>
修改虛擬主機(jī)文件后,禁用默認(rèn)的虛擬主機(jī)配置(000.default.conf),,然后啟用新的虛擬主機(jī)配置,,如下所示。
- sudo a2dissite 000-default.conf
- sudo a2ensite unixmen1.local.conf
- sudo a2ensite unixmen2.local.conf
最后,,重啟apache服務(wù)器,。
- sudo service apache2 restart
就是這樣。現(xiàn)在,,我們成功地配置了apach虛擬主機(jī)在我們的Ubuntu服務(wù)器上
測(cè)試虛擬主機(jī)
編輯/etc/hosts文件,,
- sudo vi /etc/hosts
在文件末尾添加如下所示的虛擬域名。
- 192.168.1.250 unixmen1.local
- 192.168.1.250 unixmen2.local
保存并關(guān)閉文件,。
打開你的瀏覽器并訪問http://unixmen1.local 或 http://unixmen2.local,。你將會(huì)看到我們之前創(chuàng)建的示例頁,。
Unixmen1.local 測(cè)試頁:
Unixmen2.local 測(cè)試頁
如果你想從你的遠(yuǎn)程系統(tǒng)訪問這些站點(diǎn),你需要在你的DNS服務(wù)器添加實(shí)際域名記錄,。不過,,我沒有真實(shí)的域名和DNS服務(wù)器,我只想通過我的本地系統(tǒng)測(cè)試,,那么它剛好如我所愿地工作,。
Cheers!
更多Ubuntu相關(guān)信息見Ubuntu 專題頁面 http://www./topicnews.aspx?tid=2
本文永久更新鏈接地址:http://www./Linux/2014-06/102871.htm
|