VirtualHost apache始终返回相同的网站而不是子域

时间:2016-07-04 17:34:26

标签: symfony subdomain virtualhost centos6 apache2.2

我正在使用apache 2.2.15,在CentOS 6上的虚拟机中,我有一个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)。 我错过了一些配置或什么?

1 个答案:

答案 0 :(得分:0)

您获得的错误是来自Apache的DNS而非错误。您需要在尝试浏览mysubdomain.mysite.cl的同一台计算机上修改hosts文件。

在运行浏览器的计算机上打开命令提示符/ shell,然后运行ping mysubdomain.mysite.cl如果它正常工作,您的浏览也应该正常运行。如果您收到类似ping: unknown host mysubdomain.mysite.cl(Linux)或Ping request could not find host mysubdomain.mysite.cl(Windows)的消息。然后只需编辑该系统上的hosts文件或将DNS条目添加到您的名称服务器。

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