Ubuntu #Apache2 Ubuntu 14.04 LTS系統中設定Apache虛擬機器主機

來源:互聯網
上載者:User

標籤:url   isa   多個   art   def   app   系統測試   after   個人   

虛擬機器主機常用於在一個單獨的IP地址上提供多個網域名稱的網站服務。如果有人想在單個VPS的單個IP地址運行多個網站,這是非常有用的。在這個教程中,讓我告訴你如何設定在Ubuntu 14.04 LTS的Apache網頁伺服器設定虛擬機器主機。請注意,這個教程只針對Ubuntu14.04的32位版本。

我不保證它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生版本(雖然可能過程是類似的)。
方案
在這個教程中,我會使用Ubuntu 14.04 32位 LTS,並搭建2個測試網站分別命名為“unixmen1.local” 和 “unixmen2.local”.我的測試機分別為192.168.1.250/24和server.unixmen.local。你可以根據你的需要更改虛擬網域名稱。
安裝Apache網站伺服器
安裝apache伺服器之前,我們來更新一下我們的Ubuntu伺服器:
1. sudo apt-get update
然後,用下面命令來安裝apache網路伺服器:
1. sudo apt-get install apache2
安裝apache伺服器之後,讓我們通過這個URL http://你的伺服器的IP地址/ 來測試網站伺服器是否正常工作

如你所見,apache伺服器已經工作了。
設定虛擬機器主機
1.建立虛擬目錄
現在,讓我們繼續安裝虛擬機器主機。正如我先前所述,我要建立1台虛擬機器主機分別命名為“lws.com”
建立一個公用的檔案夾來存放這兩台虛擬機器主機的資料。

接著,為網站建立一個目錄:
1. sudo mkdir -p /data/lwssite
2. 設定所有者和許可權
上面目錄現在只有root擁有許可權。我們需要修改這2個目錄的擁有權給普通使用者,而不僅僅是root使用者。
1. sudo chown -R $USER:$USER /data/lwssite/
“$USER”變數指向了當前的登入使用者。
設定讀寫權限給apache網頁根目錄(/var/www)及其子目錄,這樣每個人都可以從目錄中讀取檔案。
1. sudo chmod -R 755 /var/www/
這樣,我們就建立好了一些檔案夾來儲存網路相關資料並分配必要的許可權和所屬使用者。
3. 為虛擬機器主機建立樣本頁
現在,我們給網站增加樣本頁。第一步,讓我們給虛擬機器主機unixmen1.local建立一個樣本頁。
1. sudo vi /data/lwssite/index.html
添加以下內容:
1. <html>
2. <head>
3. <title>www.unixmen2.local</title>
4. </head>
5. <body>
6. <h1>Welcome To lws website</h1>
7. </body>
8. </html>
儲存並關閉檔案。
4. 建立虛擬機器主機設定檔
預設情況下,apache有一個預設的虛擬機器主機檔案叫000-default.conf。我們將會複製000-default.conf檔案內容到我們新的虛擬機器主機設定檔中。
1. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/lws.com.conf
確保虛擬機器主機設定檔末尾包含.conf副檔名。




[email protected]:/etc/apache2/sites-available# vi lws.com.conf

<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.lws.com ServerAdmin [email protected] DocumentRoot /data/lwssite # 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>

  


修改虛擬機器主機檔案後,禁用預設的虛擬機器主機配置(000.default.conf),然後啟用新的虛擬機器主機配置,如下所示。

sudo a2dissite 000-default.confsudo a2ensite unixmen1.local.confsudo a2ensite unixmen2.local.conf

 

最後,重啟apache伺服器。
1. sudo service apache2 restart
就是這樣。現在,我們成功地配置了apach虛擬機器主機在我們的Ubuntu伺服器上
測試虛擬機器主機
編輯/etc/hosts檔案,
1. sudo vi /etc/hosts
在檔案末尾添加如下所示的虛擬網域名稱。
1. 192.168.199.135 lws.com
儲存並關閉檔案。
開啟你的瀏覽器並訪問http://lws.com你將會看到我們之前建立的樣本頁。

如果你想從你的遠程系統訪問這些網站,你需要在你的DNS伺服器添加實際網域名稱記錄。不過,我沒有真實的網域名稱和DNS伺服器,我只想通過我的本地系統測試,那麼它剛好如我所願地工作。
Cheers!

 

Ubuntu #Apache2 Ubuntu 14.04 LTS系統中設定Apache虛擬機器主機

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.