0

What is the best way to implement a wildcard vhost using Apache in Debian so any folder I put in the /var/www/ folder will work like such

/var/www/abc will automatically point to abc.local

/var/www/wp will automatically point to wp.local

/var/www/test will automatically point to test.local

I think the only thing I would have to do is manually edit the /etc/hosts file?

1 Answer 1

0

In general, in Apache your first host is the one that will get displayed as default if no ServerName or ServerAlias.

May distros include a 000-default.conf that becomes the default vhost.

Now, for your particular needs, Looks like you're setting up a dev environment. You can use DNSMasq and apache to automagically resolve .local to localhost and tell apache to look for it under a particular directory:

wp.local -> /var/www/wp
something.local -> /var/www/something

In dnsmasq.conf:

# catch .local
address=/.local/127.0.0.1

In apache:

<Directory "/var/www/">
  AllowOverride All
  Options Indexes MultiViews FollowSymLinks
  Require all granted
</Directory>

<VirtualHost *:80>
  ServerName localhost.local
  ServerAlias *.local
  UseCanonicalName off
  VirtualDocumentRoot /var/www/%1/
</VirtualHost>

See this post for further reference. He's using OS X but should work for any *nix distribution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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