設定虛擬主機

設定虛擬主機

我目前將所有網站都放在目錄上/var/www.我想設定一個http://foo/指向該/var/www/foo/foo目錄的虛擬主機(並且仍然保留預設的本地主機行為)。

我將以下文件新增foo/etc/apache2/sites-available/

<VirtualHost *:80>
    ServerName foo
    DocumentRoot /var/www/foo/foo

    # Other directives here
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/foo/foo>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

然後我運行以下命令:

sudo a2ensite foo
sudo /etc/init.d/apache2 reload

但當我訪問它時,http://foo/它仍然返回一個 ISP 搜尋頁面。

答案1

您需要編輯/etc/hosts檔案以便http://foo解析為 127.0.0.1。

編輯文件/etc/hosts(使用 sudo/root)並添加以下行:

127.0.0.1 foo

答案2

查看https://github.com/Aslamkv/vh:)

該工具可讓您透過為您完成所有配置來新增和刪除 Ubuntu 中的虛擬主機。它簡單易用。

免責聲明:我是作者:P

答案3

對於那些使用阿帕奇的人。您將需要

Ensure you have .htaccess in root path of the site you are hosting. Example /var/www
Update the /etc/apache2/sites-available/default

<Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
</Directory>

<Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
</Directory>

希望這對某人有幫助

答案4

相關內容