Pergunta

I'm trying to get dynamic virtual hosts to work, followed the documentation but it didn't quite work.

These are the domains from my HOSTS file:

127.0.0.1 walestourism.local.co.uk
127.0.0.1 www.walestourism.local.co.uk
127.0.0.2 walestourism.local.co.uk
127.0.0.2 www.walestourism.local.co.uk

and this is from httpd.conf:

NameVirtualHost 127.0.0.2
<VirtualHost 127.0.0.2>
ServerName www.walestourism.local.co.uk
ServerAlias walestourism.local.co.uk
DocumentRoot /www/walestourism.local.co.uk
ScriptAlias /cgi-bin/ /www/walestourism.local.co.uk/cgi-bin
</VirtualHost>

In all my other ones it was always *:80 for the VirtualHost part of the above code.

I have this code in my httpd.conf:

<Directory C:/www/vhosts>   
Order Deny,Allow   
Allow from all 
AllowOverride All
</Directory>
<Directory C:/www/vhosts1>   
Order Deny,Allow   
Allow from all 
AllowOverride All
</Directory>
<Directory C:/www/vhosts.www>   
Order Deny,Allow   
Allow from all 
AllowOverride All
</Directory>
<Directory C:/www/test2>   
Order Deny,Allow   
Allow from all 
AllowOverride All
</Directory>
<Directory C:/www/>   
Order Deny,Allow   
Allow from all 
AllowOverride All
</Directory>

How should I fix this error, as when I type the domain in it takes me to the contents of http://localhost ? That's the basic problem I get when I try to add domains using dynamic virtual hosts.

Also, if I point my browser to "http://localhost/", I get the default "It Works!" page, so I know that my server is running and that this is definitely something to do with the vhosts configuration.

I checked my error log - no errors as a result of this, so why does every domain direct to localhost even when there's a folder configured for them (/www/ in this case is C:/www, my Apache/webserver's directory).

I'm new to this area of Apache, and despite an afternoon of Googling, I'm not sure how to fix this.

I decided to try this to avoid doing cmd > httpd -k restart every time I add a new virtualhost for testing, but have I done anything wrong?

I'm on Apache 2.2, using Windows 7, with PHP 5.28 [mentioning specifications here].

What should I do?

All advice is very much appreciated!

Foi útil?

Solução

As you are using named based virtual hosting, don't use 127.0.0.2 ... just keep it all to 127.0.0.1 ... failing that, check the error_log for apache (defined in your httpd.conf) to trouble shoot why it is failing.

Additionally, get Apache2 working on Windows with VHosts before you get going with PHP ...

As per http://httpd.apache.org/docs/2.0/vhosts/examples.html:

 # Ensure that Apache listens on port 80
 Listen 80

 # Listen for virtual host requests on all IP addresses
 NameVirtualHost *:80

 <VirtualHost *:80>
 DocumentRoot /www/example1
 ServerName www.example1.com
 # Other directives here
 </VirtualHost>

 <VirtualHost *:80>
 DocumentRoot /www/example2
 ServerName www.example2.org
 # Other directives here
 </VirtualHost>

Outras dicas

Normally this happens, if a virtual host is configured wrongly. As you are on windows I have no idea how to test your configuration, on linux you would do something like:

/etc/init.d/httpd configtest

try to start apache from command line and see if you get any errors. If Apache is installed as a service you can see startup errors in the windows application event logs.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top