新聞中心
在Lighttpd Server中設(shè)置VirtualHosts的方法?這個問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、網(wǎng)站建設(shè)、灌云網(wǎng)絡(luò)推廣、小程序開發(fā)、灌云網(wǎng)絡(luò)營銷、灌云企業(yè)策劃、灌云品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供灌云建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
VirtualHosting是在單個服務(wù)器上托管多個域的一種實現(xiàn)。它能夠利用服務(wù)器的最大資源并降低消耗現(xiàn)在,大多數(shù)Web服務(wù)器都支持虛擬主機環(huán)境。

在我們之前的文章中,我們介紹了在CentOS / RHEL上安裝Lighttpd服務(wù)器。本篇文章將介紹關(guān)于在Lighttpd服務(wù)器中設(shè)置VirtualHosts。
例如,我們使用以下域名:
site1.php.cn
site2.php.cn
步驟1:創(chuàng)建服務(wù)器文檔根目錄
首先為兩個域創(chuàng)建文件夾(如果不存在)
# mkdir -p /sites/vhosts/site1.php.cn/www # mkdir -p /sites/vhosts/site2.php.cn/www
出于測試目的,我們在兩個文檔根目錄中創(chuàng)建index.html文件
# echo "Welcome to Site1" > /sites/vhosts/site1.php.cn/www/index.html # echo "Welcome to Site2" > /sites/vhosts/site2.php.cn/www/index.html
步驟2:更新主配置文件
現(xiàn)在編輯Lighttpd主配置文件/etc/lighttpd/lighttpd.conf并啟用包含虛擬主機的文件。通過刪除起始#符號取消對以下行的注釋。
include_shell "cat /etc/lighttpd/vhosts.d/*.conf"
步驟3:創(chuàng)建VirtualHost配置文件
現(xiàn)在開始為兩個域或子域創(chuàng)建virutalhost配置文件,首先為site1.php.cn創(chuàng)建
# vim /etc/lighttpd/vhosts.d/site1.php.cn.conf
$HTTP["host"] == "site1.php.cn" {
server.document-root = "/sites/vhosts/site1.php.cn/public"
server.errorlog = "/var/log/lighttpd/site1.php.cn.error.log"
accesslog.filename = "/var/log/lighttpd/site1.php.cn.access.log"
}現(xiàn)在為site2.php.cn創(chuàng)建配置文件
# vim /etc/lighttpd/vhosts.d/site2.php.cn.conf
$HTTP["host"] == "site2.php.cn" {
server.document-root = "/sites/vhosts/site2.php.cn/public"
server.errorlog = "/var/log/lighttpd/site2.php.cn.error.log"
accesslog.filename = "/var/log/lighttpd/site2.php.cn.access.log"
}步驟4:驗證配置并重新啟動lighttpd
首先驗證所有配置文件的語法,包括主配置文件
# lighttpd -t -f /etc/lighttpd/lighttpd.conf Syntax OK
如果發(fā)現(xiàn)所有語法都正常,讓我們重新啟動服務(wù)。
# service lighttpd restart
完成后在瀏覽器中測試你的兩個域,并檢查是否獲得了步驟1中創(chuàng)建的頁面上的正確內(nèi)容。
感謝各位的閱讀!看完上述內(nèi)容,你們對在Lighttpd Server中設(shè)置VirtualHosts的方法大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當前文章:在LighttpdServer中設(shè)置VirtualHosts的方法
轉(zhuǎn)載源于:http://www.dlmjj.cn/article/jgjhhd.html


咨詢
建站咨詢
