VirtualHost apache 总是 returns 同一个网站不是子域

VirtualHost apache always returns same website not subdomain

我在 CentOS 6 上的虚拟机中使用 apache 2.2.15,我有一个 symfony proyect 在这里工作,我的老板想在同一台服务器的子域上加载一个 wordpress 网站。 子域不起作用,我尝试了很多配置,这是最后一个使用的:

mysite.cl.conf(在 /etc/httpd/conf.d 文件夹中)

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /var/www/html/symfonyProyect/web
    ServerName mysite.cl
    ServerAlias mysite.cl

    ErrorLog /var/log/httpd/symfonyProyect_error.log
    CustomLog /var/log/httpd/symfonyProyect_access.log combined

    <Location />
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /app.php [L]
        </IfModule>
        DirectoryIndex app.php
    </Location>

</VirtualHost>


<VirtualHost *:80>
    ServerName mysubdomain.mysite.cl

    DocumentRoot /var/www/html/mysubdomain

    <Directory /var/www/html/mysubdomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/httpd/mysubdomain_error.log
    CustomLog /var/log/httpd/mysubdomain_access.log combined
</VirtualHost>

我的主机文件(在 /etc 文件夹中)

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
myip  mysite.cl mysubdomain.mysite.cl

和我的hosts.conf

multi on

当我尝试 mysite.cl 时它显示 symfony 网站,但是当我尝试 mysubdomain.mysite.cl 时,它给了我“This site can't be reached”或“ERR_NAME_NOT_RESOLVED” .

如果我删除第一个 VirtualHost 块,它会显示 wordpress 网站(甚至使用 ServerName mysubdomain.mysite.cl)。 我是否缺少某些配置或其他内容?

您收到的错误是 DNS 错误,而不是来自 Apache 的错误。您需要在尝试浏览到 mysubdomain.mysite.cl.

的同一台计算机上修改主机文件

在您 运行 开启浏览器的机器上打开一个命令 prompt/shell,然后 运行 ping mysubdomain.mysite.cl 如果它有效,您的浏览也应该有效。如果您收到类似于 ping: unknown host mysubdomain.mysite.cl (Linux) 或 Ping request could not find host mysubdomain.mysite.cl (Windows) 的消息。然后只需编辑该系统上的主机文件或将 DNS 条目添加到您的名称服务器。

在 Apache 运行 所在的服务器上简单地编辑 /etc/hosts 不会导致所有其他主机能够将主机名解析为 IP 地址。