使用apache虚拟主机

时间:2013-08-16 15:26:41

标签: apache virtualhost

我正在尝试使用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

但这一切都无效。

1 个答案:

答案 0 :(得分:0)

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

ServerName example.com
ServerName example.net

是正确的。您只是尝试在SAME服务器名称的子目录中托管两个不同的站点。为此,您不需要两个virtualhost指令。只需一个虚拟主机中的<Directory><Location>,例如

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