Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在本地运行多个网站Apache PHP Ubuntu_Apache_Ubuntu_Virtualhost - Fatal编程技术网

在本地运行多个网站Apache PHP Ubuntu

在本地运行多个网站Apache PHP Ubuntu,apache,ubuntu,virtualhost,Apache,Ubuntu,Virtualhost,我正在尝试运行多个virtualhost(?),例如: http:/localhost将指向一个项目,http:/newsite指向另一个项目,http:/myfavorite将再次指向另一个项目和另一个文档根 (由于超链接发布限制,此处的每个http://都是http:/) 我没有在/etc/apache2中找到编辑apache文件的地方。我在找vhosts文件吗 任何建议都非常好,谢谢。localhost与apache无关,但它是您机器的别名(ip 127.x.x.x) 你必须编辑/etc/

我正在尝试运行多个virtualhost(?),例如: http:/localhost将指向一个项目,http:/newsite指向另一个项目,http:/myfavorite将再次指向另一个项目和另一个文档根

(由于超链接发布限制,此处的每个http://都是http:/)

我没有在/etc/apache2中找到编辑apache文件的地方。我在找vhosts文件吗


任何建议都非常好,谢谢。

localhost与apache无关,但它是您机器的别名(ip 127.x.x.x)

你必须编辑
/etc/hosts
,才能完成你想要的


你为什么要这么做?还不够?

您可以编辑/etc/hosts并添加指向127.0.0.1的多个名称,然后为每个名称添加VirtualHost条目。根据服务器的不同,配置文件可能位于/etc/apache2/conf/httpd.conf或/etc/apache2/sites中。如果是后者,那么这是我在配置中第一次在谷歌上大受欢迎。

这是一本电子书的一章,它解释了如何创建虚拟主机来精确地完成您想要的任务,示例是使用Ubuntu:

简言之:

  • 您首先需要创建VirtualHost
  • 然后,您必须编辑主机文件(在Linux下,它是
    /etc/hosts
    ),以便新的“伪域名”指向您的机器
对于VirtualHost,使用Ubuntu,您可以在
/etc/apache2/sites available/
中创建一个新文件;例如名为
your site.com
;它将包含如下内容:

<VirtualHost *:80>
    ServerName your-site.com
    DocumentRoot /.../www/...

    <Directory /.../www/...>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
127.0.0.1       your-site.com
然后,重新加载Apache:

sudo /etc/init.d/apache2 reload

然后,您必须编辑/etc/hosts以添加如下行:

<VirtualHost *:80>
    ServerName your-site.com
    DocumentRoot /.../www/...

    <Directory /.../www/...>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
127.0.0.1       your-site.com
所以“yoursite.com”实际上指的是你自己的电脑


重要的是,用于在浏览器中访问网站的名称是主机文件中声明的名称;它还必须与Apache配置中ServerName directivr使用的相同


当你为一个虚拟主机做了这件事。。。其他每个站点都是一样的:只有站点的名称,它是DocumentRoot,change



希望这有帮助

在dev box上设置一个合适的虚拟主机可以为您提供一个更真实的dev环境,而不仅仅是使用/var/www/中的目录。
ServerName
值必须有扩展名吗?我注意到你使用了
your site.com
,但是你能用类似
mysite
的东西吗?