當前位置:首頁 » 存儲配置 » apache可以配置哪些虛擬機

apache可以配置哪些虛擬機

發布時間: 2023-02-07 06:55:08

1. 如何配置 Apache 的虛擬主機

1、基於ip地址的虛擬主機

復制代碼代碼如下:

Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /home/httpd/html1
ServerName www.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /home/httpd/html2
ServerName www.ok2.com
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
</VirtualHost>

2、基於IP 和多埠的虛擬主機配置

復制代碼代碼如下:

Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>

DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>

3、單個IP 地址的伺服器上基於域名的虛擬主機配置

復制代碼代碼如下:

# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>

如果您感覺上面的文章還不夠詳細可以看下下面的文章:

實驗目標:在apache實現基於域名的虛擬主機
實驗用的XAMPP版本為1.7.7,內含apache版本為2.2.21

實驗前准備:

1. 為了測試不同的域名,在Windows/System32/drivers/etc/下覓得hosts文件,在其中添加實驗用的域名若干,如 -

復制代碼代碼如下:

127.0.0.1 test1.net
127.0.0.1 test2.net

如此,則在瀏覽器中輸入該倆域名時,Windows將其解析為127.0.0.1本地地址。即,在瀏覽器中訪問localhost, test1.net, test2.net均可訪問XAMPP的歡迎頁。
2. 在apache目錄下建立目錄,以放置您不同的網站。為保護XAMPP原有的htdocs中的歡迎頁內容,實驗另外建立了與htdocs平級的htdocs1目錄,在其下建立了test1.net, test2.net兩個子目錄用以放置實驗用的網站。如下 -
apache/htdocs1/test1.net - 放置test1.net網站內容
apache/htdocs1/test2.net - 放置test2.net網站內容
在這兩個目錄中各新建hello world一網頁 index.html,內容 -

復制代碼代碼如下:

<HTML>
<HEAD></HEAD>
<BODY>
<H1>hello~, 這是[對應的網站名,用以區別].net</H1></BODY>
</HTML>

實驗步驟:
1. 找到apache/conf/httpd.conf, 將其中的
ServerAdmin
ServerName
DocumentRoot
注釋掉。

2. 在httpd.conf中,找到行
Include "conf/extra/httpd-vhosts.conf"
如被注釋則解注。該文件記載了虛擬主機的參數。[以前虛擬主機參數是直接填寫在httpd.conf中的,為了更好地組織文件,將其分離出去,類似於某些編程語言一樣。因此httpd.conf中include它,即相當於把它的內容填在了httpd.conf中。]

3. 這個httpd-vhosts.conf文件格式基本如下 -

復制代碼代碼如下:

#blah-blah
NameVirtualHost *:80
#blah-blah
#blah-blah
<VirtualHost *:80>
ServerAdmin XXXXXXXX
DocumentRoot "XXXXXXXX"
ServerName XXXXXXX
ServerAlias XXXXXX
ErrorLog "logs/XXXXXX-error.log"
CustomLog "logs/XXXXXXX-error.log" combined
</VirtualHost>

需要修改的,就是<VirtualHost>中的參數了。這個可以參見apache官方文檔。根據實驗域名,可以增加兩個<VirtualHost>:

復制代碼代碼如下:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs1/test1.net"
ServerName test1.net
ServerAlias www.test1.net
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test1.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs1/test2.net"
ServerName test2.net
ServerAlias www.test2.net
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test2.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>

注意,如果不在各VirtualHost中定義Directory的可訪問性,你將遇到的是Access Forbidden!就連原來的localhost也是。

4. 由於之前注釋掉了httpd.conf中的ServerName, DocumentRoot等,為了仍然能以localhost訪問原XAMPP歡迎頁,就在增加一個VirtualHost,如下 -

復制代碼代碼如下:

<VirtualHost *:80>
ServerAdmin adm@localhost
DocumentRoot "C:/xampp/htdocs"
ServerName localhost

ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined

<Directory "C:/xampp/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>

為了避免出錯,把它放置在第一個Virtualhost位置。

至此,apache基於域名的虛擬主機配置完成。可以通過http://localhost訪問XAMPP歡迎頁,通過http://test1.net和http://test2.net訪問各自的主頁。

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs"
ServerName localhost
ServerAlias www.sky.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined

<Directory "E:/sky/apache2/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/project1"
ServerName project1.com
ServerAlias www.project1.com
ErrorLog "logs/project1-error.log"
CustomLog "logs/project1-access.log" combined

<Directory "E:/sky/apache2/htdocs/project1">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/zendTest/public"
ServerName zendTest.com
ServerAlias www.zendTest.com
DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/testRewrite"
ServerName testRewrite.com
ServerAlias www.testRewrite.com
# DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/test"
ServerName test.com
ServerAlias www.test.com
ErrorLog "logs/zendTest-error.log"
CustomLog "logs/zendTest-access.log" combined

<Directory "E:/sky/apache2/htdocs/test">
order allow,deny
allow from all
</Directory>
</VirtualHost>

2. 如何進行Apache虛擬機設置

Apache虛擬機設置有兩種方法: 基於主機名的虛擬主機(一個IP地址,多個網站) 基於IP地址的虛擬主機(每個站點擁有一個的獨立IP地址) 可能很多人沒有多個靜態ip,也沒有多個域名,也沒有線上的伺服器。我也沒有。不過我們還是可以在本機實現Apache虛擬機設置的。下面我們要用到的ip是 127.0.0.1, 127.0.0.2。域名是localhost, localhost2, localhost3打開/etc/hosts在後面添加127.0.0.1 localhost2 127.0.0.2 localhost3windows的系統是修改 C:\WINDOWS\system32\drivers\etc\hosts 文件這一步需要重啟一下機器。先重啟了再進行下邊的操作。重啟後 localhost2和localhost3就可以指向各住的ip了。打開apache配置文件。一般是在 /etc/httpd/conf/httpd.conf 或者你指定的目錄。windows的系統是在apache安裝目錄的conf文件夾里 在最後添加NameVirtualHost 127.0.0.1:80ServerAdmin [email protected] DocumentRoot /home/webroot/website1 ServerName localhostServerAdmin [email protected] DocumentRoot /home/webroot/website2 ServerName localhost2ServerAdmin [email protected] ServerName localhost3其中DocumentRoot要改成和自己機子相符的路徑。然後務必重啟apache才可以生效。 service httpd restart 重啟apache。然後用localhost localhost2 和 localhost3 就可以訪問各住的目錄了。其中NameVirtualHost 127.0.0.1:80 是需要的,否則會出現這樣的警告提示:VirtualHost 127.0.0.1:80 overlaps with VirtualHost 127.0.0.1:80, the first has precedence, perhaps you need a NameVirtualHost directive 如果需要一個虛擬機綁定多個域名,則可以在別名 ServerAlias 後面全部列出來。還可以通過 php_admin_value open_basedir 限制各自虛擬機可操作文件的目錄。同時可以通過 ErrorDocument 404 設置404錯誤頁面的位置。其他配置就不多說了,可以參考apache手冊。至此,Apache虛擬機設置就完成了。

3. 用戶apache 配置伺服器的虛擬主機,有幾種不同虛擬技術可以完成

apache是開源的web服務軟體之一,也是現在開源系統比如centos上安裝web服務常見軟體;

虛擬主機是提供網站服務的集成環境,比如:linux Apache+php+mysq LAMP
就是常說的建站開通的虛擬空間;

所以
Apache伺服器只是虛擬空間的一種架構.

4. 在虛擬機上如何配置apache

1、安裝apache:make,make install。
2、把虛擬機配置成橋接模式。
3、把虛擬機防火牆關掉。
4、把虛擬機和客戶機設置成同一個網段內。
5、啟動apache:/usr/local/apache2/bin/apachectl start
6、配置apache 的conf目錄下面的http.conf:
ServerName: 主機地址和埠
DocumentRoot:默認文檔。
7、訪問apache,成功!
如果想訪問svn,那麼加上如下東西:
打開apache的httpd.conf文件,應該在/etc/httpd/conf/httpd.conf下
將231,232行改為User apache Group apache ,如果已經改過來就不用改了。
在最後添加(注意:要在英文狀態下輸入,並且#後的注釋內容不要寫的配置文件里,否則apache啟動不了)DAV svnAuthType Basic
# SVNPath /usr/linux/xiu #單庫時需要這么寫,xiu為庫名。
SVNParentPath /usr/linux #庫路徑(多庫),根據實際情況而定。
AuthName "repos-project"
AuthUserFile "/etc/httpd/passwd" #存放用戶名及密碼的文件路徑。

熱點內容
微博如何從賬號和密碼登錄 發布:2025-07-15 15:59:02 瀏覽:122
解說電影需要哪些硬體配置 發布:2025-07-15 15:56:59 瀏覽:379
ftp快捷鍵搜索文件 發布:2025-07-15 15:51:44 瀏覽:457
蘋果賬號密碼忘了怎麼注銷 發布:2025-07-15 15:30:50 瀏覽:200
自動閱讀掛機腳本 發布:2025-07-15 15:20:18 瀏覽:848
開票人的許可權配置如何選擇 發布:2025-07-15 14:51:22 瀏覽:131
怎麼把伺服器變成普通電腦 發布:2025-07-15 14:39:45 瀏覽:958
甘肅天水首選伺服器地址雲主機 發布:2025-07-15 14:34:32 瀏覽:716
我的世界java版好玩的外國伺服器網址 發布:2025-07-15 14:20:17 瀏覽:111
電腦的外存儲器 發布:2025-07-15 14:19:42 瀏覽:527