<noframes id="7xbfr"><pre id="7xbfr"><output id="7xbfr"></output></pre>

      <big id="7xbfr"><font id="7xbfr"><listing id="7xbfr"></listing></font></big>
        <p id="7xbfr"></p>
        <menuitem id="7xbfr"></menuitem>

          <video id="7xbfr"><mark id="7xbfr"><listing id="7xbfr"></listing></mark></video>
            <form id="7xbfr"></form>

          <delect id="7xbfr"><var id="7xbfr"></var></delect>

          Apache中DocumentRoot和Directory的區別

          時間:2021-04-20 09:11:56 類型:WEB服務器
          字號:    

            在一段Apache配置中往往會出現一對令人疑惑的值,DocumentRoot和Directory,原因在于它們后面跟了一樣的路徑。

            一.虛擬主機

            以一段vhost(虛擬主機)的配置為例。該配置由軟件自動生成,由于它可以正常運行,我們從這里入手。

            
            <VirtualHost *:80>
              DocumentRoot "E:\www\public"     --①
              ServerName www.test.com
              ServerAlias 
            <Directory "E:\www\public">        --②
                Options FollowSymLinks ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
                Require all granted
            </Directory>
          </VirtualHost>
            

           ?、貲ocumentRoot代表根目錄

           ?、诖碓撃夸浀幕緦傩?/p>

            可以看到的一個現象是:①②目錄一致,且該路徑下一般都有index.php入口文件。

            二.服務器配置

            httpd.conf一般用于配置Apache的主體依賴環境。在其中有一段配置定義:

          #
          # Deny access to the entirety of your server's filesystem. You must
          # explicitly permit access to web content directories in other 
          # <Directory> blocks below.
          #
          DocumentRoot  "D:\phpStudy\WWW"
          <Directory />
              Options +Indexes +FollowSymLinks +ExecCGI
              AllowOverride All
              Order allow,deny
              Allow from all
              Require all granted
          </Directory>

            注意到包含關系,即主體配置中會包含虛擬主機標簽,可以推測出虛擬主機的設置是在全局主體配置的基礎上進行增量定義的。

            httpd.apache.org/docs/2.4/mod/core.html#directory

            在Apache的官方文檔中給出了Directory標簽的說明:定義該目錄、及子目錄的配置屬性。

            有意思的是各個屬性配置項的含義,如下:

            

           Options:復寫選項策略,可選值有Indexes、FollowSymLinks和ExecCGI等。

               分別代表"允許列舉目錄"、"允許Directory路徑定義以外的鏈接文件"、"允許執行CGI程序"。

            AllowOverride:復寫重定向策略

            Order:復寫可用指令集

            Allow:復寫可訪問網站的地址集


            三.對比結論

            實際上明白各種語法的含義后,至此答案已經明了。

            DocumentRoot屬性用于指定了一種URL映射的根目錄路徑。例如http://localhost/

            而Directory標簽是為了指定URL路徑在后續的請求中可以進行操作的權限范圍屬性。

            注意到二的一段黑字,我們將有可能把一的①②路徑寫得不一致,即DocumentRoot為子目錄,Directory為父目錄。

          <VirtualHost *:80>
              DocumentRoot "E:\www\public"
              ServerName test.com
              ServerAlias 
            <Directory "E:\www">
                Options -Indexes -FollowSymLinks +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
               Require all granted
            </Directory>
          </VirtualHost>

            在此配置文件中指定了不允許列舉目錄、禁止PHP程序訪問Directory路徑定義以外的鏈接文件、允許執行CGI程序、對根目錄授予了允許所有訪問都接受的權限。

            由于根目錄(DocumentRoot)的路徑是目錄訪問定義(Directory)的一個子目錄,理應也能正常運行。

            在E:\www\public下新建一個index.php文件,echo "Hello World"。

            啟動httpd.exe后一切正常


          黄网站免费 <