mardi 8 avril 2014

Apache : Configuration d'hôte virtuel - Stack Overflow


As i tried to configure my virtual host in apache. I put something like this,


NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

And in my hosts file i put something like this,


127.0.0.1       localhost
127.0.0.1 gift.loc

And i run it on the browser,


http://gift.loc - is fine

But when i tried using this,


http://localhost/othersite - can't found

Do i missed somehting to configure? ANy ideas...


Thanks in advance,




You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.


For example if we have:


<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /example/htdocs/gift
ServerName example.com
</VirtualHost>

A request for foobar.org will get handled by the gift.loc virtual host.




you need to put localhost in the vhosts.conf


    NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.




From the docs, it looks like we need to create a block for each different host that you would like to serve.


Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.



As i tried to configure my virtual host in apache. I put something like this,


NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

And in my hosts file i put something like this,


127.0.0.1       localhost
127.0.0.1 gift.loc

And i run it on the browser,


http://gift.loc - is fine

But when i tried using this,


http://localhost/othersite - can't found

Do i missed somehting to configure? ANy ideas...


Thanks in advance,



You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.


For example if we have:


<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /example/htdocs/gift
ServerName example.com
</VirtualHost>

A request for foobar.org will get handled by the gift.loc virtual host.



you need to put localhost in the vhosts.conf


    NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>

This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.



From the docs, it looks like we need to create a block for each different host that you would like to serve.


Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.


0 commentaires:

Enregistrer un commentaire