【问题标题】:Using apache virtual hosts使用 apache 虚拟主机
【发布时间】:2013-08-16 15:26:41
【问题描述】:

我正在尝试使用 2 个虚拟主机设置我的 apache:

Listen 11.22.33.44:8080

<VirtualHost *>
    ServerName servername.com/stable
    DocumentRoot /home/deploy/producao/servername.com/current/public
    <Directory /home/deploy/producao/servername.com/current/public>
        # This relaxes Apache security settings.
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
    </Directory>
</VirtualHost>

<VirtualHost *>
    ServerName servername.com/stable
    DocumentRoot /home/deploy/teste/servername.com/current/public
    <Directory /home/deploy/teste/servername.com/current/public>
        # This relaxes Apache security settings.
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
    </Directory>
</VirtualHost>

但一切都错了。 我想要的是,当我输入 servername.com/stable 时,我得到一个文档根目录,而当我使用 servername.com/testing 时,我得到另一个文档根目录。

我尝试了几件事,但都没有成功,比如

<VirtualHost servername.com/stable>
<VirtualHost servername.com/testing>

并使用

ServerName servername.com
ServerPath /stable
...
ServerName servername.com
ServerPath /testing

但这些都不起作用。

【问题讨论】:

    标签: apache virtualhost


    【解决方案1】:

    您的 ServerName 指令不正确。您只能使用该指令指定 DNS 主机名,NOT 服务器路径。 例如

    ServerName example.com
    ServerName example.net
    

    应该是正确的。您只是想在相同服务器名称的子目录中托管两个不同的站点。为此,您不需要两个虚拟主机指令。单个虚拟主机中只有一个 &lt;Directory&gt;&lt;Location&gt;,例如

    <VirtualHost *>
        ServerName example.com
        <Location /site1>
            ... site1 settings here
        </Location>
        <Location /site2>
            ... site2 settings here
        </Location>
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 2014-05-28
      • 2019-08-25
      • 2012-04-26
      • 2012-09-25
      • 2011-03-25
      相关资源
      最近更新 更多