NameVirtualHost causes 404 for localhost
I've managed to setup several VirtualHosts by enabling NameVirtualHost. Here's the top part of my vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
The problem is when I visit http://localhost
I get the default "It works!". If I go to http://127.0.0.1/
it defaults to http://mysite.local
I understand from the Apache Docs that why it defaults to mysite.local (matching the first VirtualHost). But I used to be able to go to http://localhost/phpmyadmin/
.
How can I get this back开发者_运维问答? Do I need to make my first VirtualHost localhost? That seems wrong...
Running apache 2.2.15 on Mac OS X (10.6.6).
UPDATE
If I comment out the following lines from my hosts file, both localhost and 127.0.0.1 go to the same place. I verified in the access log that it was indeed using ::1.
::1 localhost
fe80::1%lo0 localhost
So I suppose that handles the first issue, provided this is okay? But how can I get localhost to go to my default DocumentRoot?
How can I get this back? Do I need to make my first VirtualHost localhost? That seems wrong...
I did it like this and all seems to be working just fine, without needing an extra port to listen on.
The first VirtualHost block handles any URL that doesn't point to one of the 2 vhosts (2nd and 3rd VirtualHost blocks) I have set up:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/"
ServerName imputation.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/"
ServerName documentatiebestand.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
No, you can't mix VirtualHosts with "classic" configuration. You could listen on another port and define another VirtualHost (*:8080 for example) "emulating" your previous "localhost" going to your general DocumentRoot declaration.
Something like this:
Listen 80 (already declared elsewhere)
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /same/as/the/classic/one/
...
</VirtualHost>
You could also declare some Alias /phpmyadmin/ which would be global be I don't recommend aliases because you couldn't have another phpmyadmin folder in one of your vhosts.
You can of course define a phpmyadmin.local vhost ;-)
精彩评论