自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在Ubuntu 14.04 LTS系統(tǒng)中設(shè)置Apache虛擬主機

系統(tǒng) Linux
虛擬主機常用于在一個單獨的IP地址上提供多個域名的網(wǎng)站服務(wù)。如果有人想在單個VPS的單個IP地址運行多個網(wǎng)站,這是非常有用的。在這個教程中,讓我告訴你如何設(shè)置在Ubuntu 14.04 LTS的Apache網(wǎng)頁服務(wù)器設(shè)置虛擬主機。請注意,這個教程只針對Ubuntu14.04的32位版本。

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

我不保證它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生版本(雖然可能過程是類似的)。

方案

在這個教程中,我會使用Ubuntu 14.04 32位 LTS,并搭建2個測試網(wǎng)站分別命名為“unixmen1.local” 和 “unixmen2.local”.我的測試機分別為192.168.1.250/24和server.unixmen.local。你可以根據(jù)你的需要更改虛擬域名。

安裝Apache網(wǎng)站服務(wù)器

安裝apache服務(wù)器之前,我們來更新一下我們的Ubuntu服務(wù)器:

  1. sudo apt-get update

然后,用下面命令來安裝apache網(wǎng)絡(luò)服務(wù)器:

  1. sudo apt-get install apache2

安裝apache服務(wù)器之后,讓我們通過這個URL http://你的服務(wù)器的IP地址/ 來測試網(wǎng)站服務(wù)器是否正常工作 

如你所見,apache服務(wù)器已經(jīng)工作了。

設(shè)置虛擬主機

1.創(chuàng)建虛擬目錄

現(xiàn)在,讓我們繼續(xù)安裝虛擬主機。正如我先前所述,我要新建2臺虛擬主機分別命名為“unixmen1.local”和“unixmen2.local”.

創(chuàng)建一個公用的文件夾來存放這兩臺虛擬主機的數(shù)據(jù)。

首先,讓我們?yōu)閡nixmen1.local這個站點創(chuàng)建一個目錄:

  1. sudo mkdir -p /var/www/unixmen1.local/public_html

接著,為for unixmen2.local站點創(chuàng)建一個目錄:

  1. sudo mkdir -p /var/www/unixmen2.local/public_html

2. 設(shè)置所有者和權(quán)限

上面目錄現(xiàn)在只有root擁有權(quán)限。我們需要修改這2個目錄的擁有權(quán)給普通用戶,而不僅僅是root用戶。

  1. sudo chown -R $USER:$USER /var/www/unixmen1.local/public_html/
  2. sudo chown -R $USER:$USER /var/www/unixmen2.local/public_html/

“$USER”變量指向了當(dāng)前的登錄用戶。

設(shè)置讀寫權(quán)限給apache網(wǎng)頁根目錄(/var/www)及其子目錄,這樣每個人都可以從目錄中讀取文件。

  1. sudo chmod -R 755 /var/www/

這樣,我們就創(chuàng)建好了一些文件夾來保存網(wǎng)絡(luò)相關(guān)數(shù)據(jù)并分配必要的權(quán)限和所屬用戶。

3. 為虛擬主機創(chuàng)建示例頁

現(xiàn)在,我們給網(wǎng)站增加示例頁。第一步,讓我們給虛擬主機unixmen1.local創(chuàng)建一個示例頁。

給unixmen1.local虛擬主機創(chuàng)建一個示例頁,

  1. sudo vi /var/www/unixmen1.local/public_html/index.html

添加以下內(nèi)容:

  1. <html>
  2. <head>
  3. <title>www.unixmen1.local</title>
  4. </head>
  5. <body>
  6. <h1>Welcome To Unixmen1.local website</h1>
  7. </body>
  8. </html>

保存并關(guān)閉文件。

同樣的,添加示例頁到第二臺虛擬主機。

  1. sudo vi /var/www/unixmen2.local/public_html/index.html

添加以下內(nèi)容:

  1. <html>
  2. <head>
  3. <title>www.unixmen2.local</title>
  4. </head>
  5. <body>
  6. <h1>Welcome To Unixmen2.local website</h1>
  7. </body>
  8. </html>

保存并關(guān)閉文件。

4. 創(chuàng)建虛擬主機配置文件

默認情況下,apache有一個默認的虛擬主機文件叫000-default.conf。我們將會復(fù)制000-default.conf文件內(nèi)容到我們新的虛擬主機配置文件中。

  1. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.conf
  2. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen2.local.conf

確保虛擬主機配置文件末尾包含.conf擴展名。

現(xiàn)在,修改unximen1.local.conf文件以符合需求。

  1. sudo vi /etc/apache2/sites-available/unixmen1.local.conf

使相關(guān)的變化直接呈現(xiàn)在unixmen1站點中(譯注:以“#”開頭的注釋行可以忽略。)。

  1. <VirtualHost *:80>
  2. # The ServerName directive sets the request scheme, hostname and port that
  3. # the server uses to identify itself. This is used when creating
  4. # redirection URLs. In the context of virtual hosts, the ServerName
  5. # specifies what hostname must appear in the request's Host: header to
  6. # match this virtual host. For the default virtual host (this file) this
  7. # value is not decisive as it is used as a last resort host regardless.
  8. # However, you must set it for any further virtual host explicitly.
  9. #ServerName www.example.com
  10.  
  11. ServerAdmin webmaster@unixmen1.local
  12. ServerName unixmen1.local
  13. ServerAlias www.unixmen1.local
  14. DocumentRoot /var/www/unixmen1.local/public_html
  15.  
  16. # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  17. # error, crit, alert, emerg.
  18. # It is also possible to configure the loglevel for particular
  19. # modules, e.g.
  20. #LogLevel info ssl:warn
  21.  
  22. ErrorLog ${APACHE_LOG_DIR}/error.log
  23. CustomLog ${APACHE_LOG_DIR}/access.log combined
  24.  
  25. # For most configuration files from conf-available/, which are
  26. # enabled or disabled at a global level, it is possible to
  27. # include a line for only one particular virtual host. For example the
  28. # following line enables the CGI configuration for this host only
  29. # after it has been globally disabled with "a2disconf".
  30. #Include conf-available/serve-cgi-bin.conf
  31. </VirtualHost>

同理,修改第二臺主機文件。

  1. sudo vi /etc/apache2/sites-available/unixmen2.local.conf

使相關(guān)的修改在unixmen2 站點呈現(xiàn)出來。

  1. <VirtualHost *:80>
  2. # The ServerName directive sets the request scheme, hostname and port that
  3. # the server uses to identify itself. This is used when creating
  4. # redirection URLs. In the context of virtual hosts, the ServerName
  5. # specifies what hostname must appear in the request's Host: header to
  6. # match this virtual host. For the default virtual host (this file) this
  7. # value is not decisive as it is used as a last resort host regardless.
  8. # However, you must set it for any further virtual host explicitly.
  9. #ServerName www.example.com
  10.  
  11. ServerAdmin webmaster@unixmen2.local
  12. ServerName unixmen2.local
  13. ServerAlias www.unixmen2.local
  14. DocumentRoot /var/www/unixmen2.local/public_html
  15.  
  16. # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  17. # error, crit, alert, emerg.
  18. # It is also possible to configure the loglevel for particular
  19. # modules, e.g.
  20. #LogLevel info ssl:warn
  21.  
  22. ErrorLog ${APACHE_LOG_DIR}/error.log
  23. CustomLog ${APACHE_LOG_DIR}/access.log combined
  24.  
  25. # For most configuration files from conf-available/, which are
  26. # enabled or disabled at a global level, it is possible to
  27. # include a line for only one particular virtual host. For example the
  28. # following line enables the CGI configuration for this host only
  29. # after it has been globally disabled with "a2disconf".
  30. #Include conf-available/serve-cgi-bin.conf
  31. </VirtualHost>

修改虛擬主機文件后,禁用默認的虛擬主機配置(000.default.conf),然后啟用新的虛擬主機配置,如下所示。

  1. sudo a2dissite 000-default.conf
  2. sudo a2ensite unixmen1.local.conf
  3. sudo a2ensite unixmen2.local.conf

最后,重啟apache服務(wù)器。

  1. sudo service apache2 restart

就是這樣?,F(xiàn)在,我們成功地配置了apach虛擬主機在我們的Ubuntu服務(wù)器上

測試虛擬主機

編輯/etc/hosts文件,

  1. sudo vi /etc/hosts

在文件末尾添加如下所示的虛擬域名。

  1. 192.168.1.250 unixmen1.local
  2. 192.168.1.250 unixmen2.local

保存并關(guān)閉文件。

打開你的瀏覽器并訪問http://unixmen1.local 或 http://unixmen2.local。你將會看到我們之前創(chuàng)建的示例頁。

Unixmen1.local 測試頁:

Unixmen2.local 測試頁

如果你想從你的遠程系統(tǒng)訪問這些站點,你需要在你的DNS服務(wù)器添加實際域名記錄。不過,我沒有真實的域名和DNS服務(wù)器,我只想通過我的本地系統(tǒng)測試,那么它剛好如我所愿地工作。

Cheers!


via: http://www.unixmen.com/setup-virtual-hosts-apache-ubuntu-14-04-lts/

譯者:disylee 校對:wxy

責(zé)任編輯:黃丹 來源: Linux中國
相關(guān)推薦

2011-08-16 15:16:26

UbuntuApache虛擬主機

2009-11-25 10:18:25

linuxapache tomc虛擬主機

2014-04-18 09:38:43

Ubuntu 14.0Trusty Tahr

2014-05-20 10:24:44

2013-10-21 10:48:12

UbuntuUbuntu 14.0Ubuntu 14.0

2010-01-11 11:19:28

Apache配置

2014-06-03 10:10:11

Ubuntu 14.0

2014-03-17 09:44:09

2017-08-15 15:24:21

2014-05-14 11:45:29

Ubuntu 14.0

2014-04-01 09:44:16

Ubuntu 14.0

2010-07-01 13:35:51

vsftpd

2014-03-05 11:45:15

Ubuntu 14.0

2014-04-15 10:34:38

Ubuntu 14.0

2009-09-04 11:03:42

2021-09-24 08:55:34

LinuxUbuntu 14.016.04 LTS

2010-03-02 13:35:59

Fedora apac

2011-05-17 15:03:34

JSP

2021-09-17 11:20:27

LinuxJava 17 LTSUbuntu

2010-03-29 16:17:07

Nginx虛擬主機
點贊
收藏

51CTO技術(shù)棧公眾號