Currently I'm hosting my own (ubuntu) server with the following services: samba, ftp and a webserver. I've bought a domain and linked the DNS A-record to my ISP's IP. This is working correctly. Now I'd like to use the DNS wildcard-record to create subdomains. I want to avoid waiting 24hrs before the DNS change completes.
Thusfar I'm only able to redirect all incoming wildcards to the same directory:
test1.domain.com redirects to /var/www
test2.domain.com redirects to /var/www
Although I'd like to get:
test1.domain.com redirects to /var/www/test1
test2.domain.com redirects to /var/www/test2
My guess would be to change the file /etc/apache2/sites-available/domain.
Any help or tips would be welcome!
Thanks,
Mark
EDIT:
This is what my /etc/apache2/sites-available/domain file looks like:
<VirtualHost *:80>
ServerAdmin webmaster@domain
DocumentRoot /var/www/webroot
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/webroot>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Best Answer
You should be able to get the desired behavior with
VirtualDocumentRoot
.Within your
<VirtualHost>
, add aServerAlias
to catch all the domains you're interested in:...then map them to the desired directories. Remove your
DocumentRoot
, and in its place, add:You'll want to have a
<Directory /var/www/>
block allowing access, and keep in mind that this vhost should only be handling service for your dynamically configured vhosts - if you wantexample.com
andwww.example.com
to be handled separately, then you'll want them to have their own<VirtualHost>
.Edit:
You'll want to use a different vhost to handle the "base" domains. Building off of the current config in the comment: