apache子網域配置

apache子網域配置

我在 CentOS 下的 apache 中設定子網域時似乎遇到了一個小問題。

我有以下內容:

NameVirtualHost *:80

<VirtualHost *>
  ServerName www.domain.co.uk
  ServerAlias domain.co.uk dev.domain.co.uk
   DocumentRoot "/var/www/html/domain/web"
   DirectoryIndex index.php
   Alias /sf /var/www/html/symfony14/web/sf

 <Directory "/var/www/html/domain/web">
   AllowOverride All
   Allow from All
 </Directory>
</VirtualHost>

<Directory "/var/www/html/symfony14/web/sf">
 AllowOverride All
 Allow from All
</Directory>
<VirtualHost *>
  ServerName test.domain.co.uk
  DocumentRoot "/var/www/html/domain_test/web"
  DirectoryIndex index.php
  Alias /sf /var/www/html/symfony14/web/sf

  <Directory "/var/www/html/domain_test/web">
   AllowOverride All
   Allow from All
  </Directory>
</VirtualHost>

因此,請造訪 www.domain.co.uk 和 domain.co.uk 將顯示 /var/www/html/domain 中的內容,但造訪 test.domain.co.uk 也會顯示相同的資料夾內容。

這是因為嗎ServerAlias

謝謝

更新:

新增了缺少的指令NameVirtualHost *:80

答案1

嘗試將其NameVirtualHost *:80 作為第一行放入設定檔中。

您可以透過以下方式設定子網域基於名稱的虛擬主機httpd.conf 中的條目。若要使用基於名稱的虛擬主機,您必須在將接受主機請求的伺服器上指定 IP 位址(可能還包括連接埠)。這是使用以下配置的名稱虛擬主機指示。

欲了解更多信息,請參閱子網域配置

答案2

好吧,它們應該顯示相同的內容,因為 DocumentRoot 是相同的。

我想對於測試域它應該是DocumentRoot "/var/www/html/domain_test/web" 而不是DocumentRoot "/var/www/html/domain/web"

相關內容