Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I can't seem to get a wildcard vhost working on my local apache installation. My vhosts file currently has the contents below. After I edit it, I'm making sure to restart the server but have still had no luck getting it to work.

Basically, I'm trying to get *.joshholat.local to point to somewhere different than joshholat.local just to make sure the config is working.

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin jholat@gmail.com
    DocumentRoot "/opt/local/www"
    ServerName joshholat.local
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin jholat@gmail.com
    DocumentRoot "/opt/local/www/phpmyadmin"
    ServerName joshholat.local
    ServerAlias *.joshholat.local
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>
share|improve this question

1 Answer 1

Right now you have two virtual hosts with the same ServerName directive

Change

    ServerName joshholat.local

in the second vhost to

    ServerName www.joshholat.local

I would probably set different logfiles for each vhost also

So your config reads:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin jholat@gmail.com
    DocumentRoot "/opt/local/www"
    ServerName joshholat.local
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin jholat@gmail.com
    DocumentRoot "/opt/local/www/phpmyadmin"
    ServerName www.joshholat.local
    ServerAlias *.joshholat.local
    ErrorLog "logs/phpmyadmin_error.log"
    CustomLog "logs/phpmyadmin_access.log" common
</VirtualHost>
share|improve this answer
    
Still no luck. Is it because I'm on localhost and need to edit my hosts file? It currently has joshholat.local pointing to 127.0.0.1. Does that not get all subdomains as well? –  joshholat Feb 12 '12 at 18:05
    
What exactly happens when you try to connect to whatever.joshholat.local? Do you have your DNS or hosts records in place? Try to ping www.joshholat.local –  Mathias R. Jessen Feb 12 '12 at 18:12
    
I think it is a hosts file issue. I added www.joshholat.local to the hosts file, and that now goes to the correct folder on my localhost. However, no wildcards on that domain are working (i.e. test.joshholat.local). I'm fairly certain it's because they aren't set to point to 127.0.0.1 in my hosts file. And I don't think it's possible to set a wildcard in a hosts file, is it? –  joshholat Feb 12 '12 at 18:19
1  
No that only works with DNS records, not hosts file entries :-) If you're not planning on using DNS you'll need to add all entries for subdomains of joshholat.local to the hosts file manually –  Mathias R. Jessen Feb 12 '12 at 18:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.