設定子網域 Apach2 Ubuntu 10.04。目前未使用虛擬主機

設定子網域 Apach2 Ubuntu 10.04。目前未使用虛擬主機

我有一個 ubuntu 10.04 伺服器,目前設定僅用於運行單一網站。我想設定一個子網域來指向該網站的特定部分。例如,我希望 test.example.com 指向 example.com/testing。實現這一目標的最佳方法是什麼?

答案1

建立一個新的虛擬主機:

touch /etc/apache2/sites-available/test.example.com

給它一些內容:

<VirtualHost *:80>
    ServerName test.example.com
    DocumentRoot /var/www/test
    # ..any other config needed
    <Directory /var/www/test>
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

啟用它:

a2ensite test.example.com

並重新啟動 Apache:

service apache2 restart

確保新test.example.com名稱的名稱解析正確指向您的伺服器。

相關內容