设置虚拟主机


10

目前,我所有的网站都位于目录下/var/www。我想设置一个http://foo/指向/var/www/foo/foo目录的虚拟主机(并仍然保留默认的localhost行为)。

我将以下文件添加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搜索页面。

Answers:


15

您需要编辑/etc/hosts文件,以便http://foo解析为127.0.0.1。

编辑文件/etc/hosts(使用sudo / root)并添加以下行:

127.0.0.1 foo


0

对于那些使用apache的人。您将需要

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>

希望这可以帮助某人


这两个directory区块不应该不同吗?
gion_13 2014年

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.