设置虚拟主机

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

我将以下文件foo添加到/etc/apache2/sites-available/

  ServerName foo DocumentRoot /var/www/foo/foo # Other directives here  Options FollowSymLinks AllowOverride None   Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all   

然后我运行以下命令:

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

但是当我去http://foo/它仍然返回一个ISP搜索页面。

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

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

 127.0.0.1 foo 

结帐https://github.com/Aslamkv/vh 🙂

此工具允许您通过为您执行每个配置来添加和删除Ubuntu中的虚拟主机。 它简单易用。

免责声明: 我是作者:P

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

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

  Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all  

  Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all  

希望这有助于某人