中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

如何配置apache虛擬主機的實例小結

2022-10-10    分類: 虛擬主機

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

 

復制代碼 代碼如下:

Listen 80

    DocumentRoot /home/httpd/html1
    ServerName www.ok1.com
    ErrorLog /usr/local/apache/logs/error1_log
    CustomLog /usr/local/apache/logs/access1_log combined


    DocumentRoot /home/httpd/html2
    ServerName www.ok2.com
    ErrorLog /usr/local/apache/logs/error2_log
    CustomLog /usr/local/apache/logs/access2_log combined

 

 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


 DocumentRoot /www/example1-80
 ServerName www.example1.com



 DocumentRoot /www/example1-8080
 ServerName www.example1.com


 DocumentRoot /www/example2-80
 ServerName www.example1.org


 DocumentRoot /www/example2-8080
 ServerName www.example2.org

 

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

復制代碼 代碼如下:

# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here


DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here

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

實驗目標:在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,內容 -

 

復制代碼 代碼如下:




hello~, 這是[對應的網站名,用以區別].net


 

 

實驗步驟:

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

    ServerAdmin XXXXXXXX
    DocumentRoot "XXXXXXXX"
    ServerName XXXXXXX
    ServerAlias XXXXXX
    ErrorLog "logs/XXXXXX-error.log"
    CustomLog "logs/XXXXXXX-error.log" combined

 

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

 

復制代碼 代碼如下:


    ServerAdmin adm@test1.net
    DocumentRoot "C:/xampp/htdocs1/test1.net"
    ServerName test1.net
    ServerAlias www.test1.net
    ErrorLog "logs/test1-error.log"
    CustomLog "logs/test1-access.log" combined

   
    order allow,deny
    allow from all
   



    ServerAdmin adm@test2.net
    DocumentRoot "C:/xampp/htdocs1/test2.net"
    ServerName test2.net
    ServerAlias www.test2.net
    ErrorLog "logs/test1-error.log"
    CustomLog "logs/test1-access.log" combined

   
    order allow,deny
    allow from all
   

 

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

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

 

復制代碼 代碼如下:


    ServerAdmin adm@localhost
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost

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

   
    order allow,deny
    allow from all
   

 

為了避免出錯,把它放置在第一個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
#
# 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 block.
#


    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs"
    ServerName localhost
    ServerAlias www.skydao.com
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined

   
    order allow,deny
    allow from all
   


    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/project1"
    ServerName project1.com
    ServerAlias www.project1.com
    ErrorLog "logs/project1-error.log"
    CustomLog "logs/project1-access.log" combined

   
    order allow,deny
    allow from all
   


    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/zendTest/public"
    ServerName zendTest.com
    ServerAlias www.zendTest.com
    DirectoryIndex index.php
   
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
   


    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/testRewrite"
    ServerName testRewrite.com
    ServerAlias www.testRewrite.com
    # DirectoryIndex index.php
   
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
   


    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/test"
    ServerName test.com
    ServerAlias www.test.com
    ErrorLog "logs/zendTest-error.log"
    CustomLog "logs/zendTest-access.log" combined

   
    order allow,deny
    allow from all
   

標題名稱:如何配置apache虛擬主機的實例小結
文章來源:http://m.2m8n56k.cn/news/204313.html

網站建設、網絡推廣公司-創新互聯,是專注品牌與效果的網站制作,網絡營銷seo公司;服務項目有虛擬主機

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網頁設計公司
主站蜘蛛池模板: 国产欧美视频一区二区三区 | 中文字幕精品在线观看 | 久久精品免视看国产明星 | 午夜免费片在线观看不卡 | 99在线观看精品 | 清纯唯美综合网 | 国产成人高清视频在线观看免费97 | 日日噜噜噜夜夜爽爽狠狠69 | 一区二区三区免费视频播放器 | 国产成人精品一区二三区在线观看 | 99久久国产综合精品成人影院 | 欧美aⅴ在线 | 日本在线不卡免 | 久久久久欧美国产精品 | 亚洲精品久久久久影 | 亚洲第一色网 | 高清成人爽a毛片免费网站 高清大学生毛片一级 | 高清不卡日本v在线二区 | 国内自拍在线观看 | 一级毛片aaa片免费观看 | 婷婷尹人香蕉久久天堂 | 国产精品99久久久久久小说 | 亚洲欧美日韩精品高清 | 亚洲免费成人在线 | 国产成人女人视频在线观看 | 一级啪啪片| 在线亚洲综合 | 3d动漫精品成人一区二区三 | 日韩午夜在线观看 | 欧美成人福利 | 午夜国产亚洲精品一区 | 日本一区二区三区四区五区 | 久久国内精品自在自线软件 | 国产女主播在线 | 高清欧美日本视频免费观看 | 日韩免费毛片全部不收费 | 国产精品成aⅴ人片在线观看 | 国产免费资源 | 久久精品视频日本 | cao草棚视频网址成人 | 欧美在线观看成人高清视频 |