Pregunta

I'm using Zend Server CE 5.6.0 on Mac OSX.

My httpd.conf has the following line, adding the virtual hosts file:

Include conf/extra/httpd-vhosts.conf

At that file, I have the following:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localtextil.drupal.lh
    DocumentRoot /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal
</VirtualHost>

So, by definition, when I try to access localtextil.drupal.lh, it should redirect me to its document root.

The problem is, when I try to access that host, I got an error.

And when I simply access localhost, I go to the site located on /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal.

What am I doing wrong here?

¿Fue útil?

Solución

Two things - first is that the virtualhost definitions (as I understand it) override apache's mappings between directories and servernames. The first defined virtualhost is what apache will use as a default when it can't find a map - so it should be a generic setup (reflecting your original domainname, in your case, localhost) first, then your specific setup following it.

Second is that if your folder is outside of where you have given apache permissions to read, then you may get an error. The directory permissions are set by a DocumentRoot directive - however:

Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a container and list it first in the configuration file.

The Apache document page on name based virtual hosting is here, it should help give some ideas. Basically you need to look at the definitions you have for DocumentRoot and the servernames, and go through them making sure they are all "ok".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top