茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1672478 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00132.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]Apache架設虛擬網站

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Apache架設虛擬網站
Apache - VirtualHost
架設虛擬網站




本文件持續編修中,若有發現謬誤或侵犯您的權益,敬請批評指教

  
40272





  1. 目的:





    • 僅使用一個
      IP
      ,只在
      DNS
      上設定不同的別名
      (CNAME)
      ,並將每一個別名分別架設成獨立的網站。實際上,這些不同的獨立網站都架設在同一個
      IP
      的主機上。
    • 申請個人網域後(bsdlab.idv.tw),在原有主機上(163.19.224.120)加設虛擬主機為個人網站(http://tim.bsdlab.idv.tw/)。


  2. 變換成 
    root
     身份操作:



    su - root




  3. 更改

    DNS
    正解檔
    的內容,設定虛擬網站所對應的別名(CNAME):



  4. dns    IN   A        163.19.224.120   這個IP的名稱是dns,是本尊;


    www    IN   CNAME    dns              這是第一個別名(CNAME)--分身;


    www1   IN   CNAME    dns              這是第二個別名(CNAME)--分身;


    www2   IN   CNAME    dns              這是第三個別名(CNAME)--分身。



  5. 修改完
    DNS
    的設定後,要記得將序號累進並
    ReLoad.





  6. kill   -HUP   `cat /var/run/named.pid`





  7. httpd.conf
    的修改:





  8. ### Section 3: Virtual Hosts
    #
    # VirtualHost: If you want to maintain multiple domains/hostnames on your
    # machine you can setup VirtualHost containers for them.
    # Please see the documentation at <URL:http://www.apache.org/docs/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.
    #
    # If you want to use name-based virtual hosts you need to define at
    # least one IP address (and port number) for them.
    #
    # 宣告虛擬網站所要使用的IP
    NameVirtualHost 163.19.224.120

    # 第一個虛擬網站(即原來的主網站名稱)
    <VirtualHost www.dnes.mlc.edu.tw>
    DocumentRoot /usr/local/www/data
    ServerName www.dnes.mlc.edu.tw
    </VirtualHost>
    # 第二個虛擬網站
    <VirtualHost www1.dnes.mlc.edu.tw>
    DocumentRoot /home/tch/tim/www/www1
    ServerName www1.dnes.mlc.edu.tw
    </VirtualHost>
    # 第三個虛擬網站
    <VirtualHost www2.dnes.mlc.edu.tw>
    DocumentRoot /home/tch/tim/www/www2
    ServerName www2.dnes.mlc.edu.tw
    </VirtualHost>
    # 第四個虛擬網站,向TWNIC申請個人網域後,在此設定虛擬主機。
    <VirtualHost tim.bsdlab.idv.tw>
    ServerAdmin root@dnes.mlc.edu.tw
    DocumentRoot /home/tch/tim/public_html
    ServerName tim.bsdlab.idv.tw
    DirectoryIndex bsdlab.htm
    </VirtualHost>
    # 這個動作有點像公司行號註冊一個網域名稱後,再向ISP租用主機一樣。


  9. 重新啟動 
    Apache
     




  10. apachectl   restart



  11. 測試一下吧:





  12. http://www.dnes.mlc.edu.tw/


    http://www1.dnes.mlc.edu.tw/


    http://www2.dnes.mlc.edu.tw/


    http://tim.bsdlab.idv.tw/



  13. 我可沒騙你喔,請用

    nslookup
    查一下上述四個網址,其結果均會回應同一個
    IP





  14. 成功與否的主要關鍵:



  15. 您的
    DNS
    是否自行控管是虛擬網站能否成功的最大關鍵,
    DNS
    有自行控管,就能隨心所欲地設定相關主機的正解對應資料,後續
    Apache
    的設定才能生效。不然,您得必須有一個配合度很高的
    ISP
    了。




原文出處:Apache - VirtualHost 架設虛擬網站 @ 苗栗縣大湖鄉大南國民小學全球資訊網路架站日誌
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]配置 Apache 支援多個網域
配置 Apache 支援多個網域

何謂 Virtual Hosting?
Virtual Hosting 就是同一台伺服器可以同時處理超過一個網域(domain)。即是說,假設 www.example1.netwww.example2.net 兩個網域都指向同一部電腦,如果電腦上的網頁伺服器 (WWW Server) 支援 Virtual Hosting,那您用 www.example1.netwww.example2.net 去訪問同一個伺服器就可以取得不同的網站。

IP-based 和 Host-based Virtual Hosting
本身 Virtual Hosting 技術分 IP-based 和 Host-based。IP-based Virtual Hosting 是指運行網站伺服器的電腦有多個 IP 地址(IP Address),訪問不同的 IP 地址就可以取得不同的網站。Host-based Virtual Hosting 則是指在 DNS 上多個網域都是指向同一個 IP 地址,網頁瀏覽器(WWW Browser)透過 HTTP 協定告知網頁伺服器要訪問那個網站。

一來 IP-based Virtual Hosting 需要多 IP 地址,即每個網站都要多點成本,二來 Host-based Virtual Hosting 技術已有十年多,現存所有網頁瀏覽器和網頁伺服器都有支援,所以現時很少人會採用 IP-based Virtual Hosting。不過因為 TLS/SSL 技術限制了每一個 IP 地址只可以支援一張電子證書(Digital Certificate),所以如果您要在同一部電腦使用多過一張電子證書,您仍然需要 IP-based Virtual Hosting。

當然您亦可以將 IP-based 及 Host-based Virtual Hosting 混合使用於同一台 Apache 網頁伺服器中。


Fedora Linux 或 Red Hat Linux 的 Apache
確定在 Apache 配置檔案 /etc/httpd/conf/httpd.conf 的"NameVirtualHost *"前的 "#" 已被刪去:
NameVirtualHost *:80

在 /etc/httpd/conf/httpd.conf 的尾部加入以下內容:
<VirtualHost *>
    # 在 ServerName 後加上您的網站名稱
    ServerName www.examples.net
    # 如果您想多個網站名稱都取得相同的網站,可以加在 ServerAlias 後加上其他網站別名。
    # 別名間以空格間開。
    ServerAlias web.examples.net mail.examples.net
    # 在 ServerAdmin 後加上網站管理員的電郵地址,方便別人有問題是可以聯絡網站管理員。
    ServerAdmin webmaster@examples.net

    # 在 DocumentRoot 後加上存放網站內容的目錄路徑
    DocumentRoot /var/www/www.examples.net
    <Directory /var/www/www.examples.net>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/httpd/access.log combined
    ServerSignature On
</VirtualHost>

記謹建立您在以上配置檔中所提到的目錄,例如 /var/www/www.examples.net 。
# mkdir /var/www/www.examples.net

檢查您的配置檔中是否有任何語法錯誤:
# apachectl configtest

重新啟動 Apache 。
# /etc/init.d/httpd reload


原文出處:配置 Apache 支援多個網域 - OSWikiHK
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Virtual Host: 如何在同一個 IP (伺服器)上以不同的 Domain Name 架設多個網站

Virtual Host: 如何在同一個 IP (伺服器)上以不同的 Domain Name 架設多個網站

Posted by HP 
「多個網站或 Domain 架在同一個 IP 上」在 Apache 的術語中稱作 Name-based Virtual Host。另外還有 IP-based Virtual Host,不過比較不常用,Name-based Virtual Host 也才是本文的介紹主題 (Name-based 顧名思義即指 Domain Name)。

作法很簡單,若假設 Apache Server 已經正常地運作了,只需修改 httpd.conf 檔案中間的幾個部份。

以下以將 www.example1.comwww.example2.com 架在同一個 Apache Server 底下的設定作為例子。



NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here / 可於此加入其他所需目錄,例如 CGI Script 的目錄

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org

# Other directives here

</VirtualHost>


若進來的 HTTP Request 的 ServerName 不是上述二者,以置於前的 www.example1.com 為主。

另請注意:不同的 Linux Distribution 的 Apahce 設定方式略有不同,例如 openSUSE 的設定主要是在

/etc/apache2/default-server.conf(需在檔中(最後)加入 NameVirtualHost *:80),

同時 Virtual Host 的設定是在

/etc/apache2/vhosts.d/*.conf

(需在該目錄新增 .conf 檔,加上上述之 Script)。因此,不同的 Linux Distribution 請注意其中可能的差別,但其原理相同。


Refereces:
Official Page: VirtualHost Examples
Official Paeg:
Name-based Virtual Host Support




原文出處:Virtual Host: 如何在同一個 IP (伺服器)上以不同的 Domain Name 架設多個網站 - Apache HTTP Server論壇 | 美寶論壇 MEPO Forum
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Apache 多站點 Virtual Host 設定

Apache 多站點 Virtual Host 設定

咕狗了許久

結果發現Apache文件裡就有寫了
我需要的是 多個不同的網址 可以連到同一個IP的不同目錄上
Name-based Virtual Host Support
目前是Apache 2.2的

在 /etc/httpd/conf.d/ 目錄中
建立一個新的檔案 檔名隨意 副檔名必須是.conf
(我是設定vhost.conf)
將以下的碼寫進去

或是

直接在 /etc/httpd/conf/httpd.conf 檔案最後面加上以下的碼



NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

ServerName 當然就是網址
ServerAlias 其他網址也可以連到同一個目錄
DocumentRoot 目錄的位置

加完記得重新啟動Apache
( /etc/init.d/httpd restart )

如果啟動的過程中有[warn]說 什麼has no VirtualHost
可以在 /etc/httpd/conf/httpd.conf 裡面找找看
有沒有一行是
NameVirtualHost *:80
將這行註解起來 再重新啟動一次

參考資料:
http://httpd.apache.org/docs/current/vhosts/name-based.html
http://linux.vbird.org/linux_server/0360apache.php
http://freebsd.lab.mlc.edu.tw/apache/VirtualHost.shtml


原文出處: Apache 多站點 Virtual Host 設定 | [lifeIs: tooShort to: waste]


泠日補充:
如果設定有任何錯漏與疑惑,請愛用:

httpd -S

依照 Apache 官方的說法(a synonym for -t -D DUMP_VHOSTS)就是可以幫你檢查 httpd.conf 如何解讀你的設定囉。
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|