[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: NameVirtualHost and dynamic subdomains on apache.



Not really a 64-bit-specific question, but I'll answer it anyway because I 
know how to do this.

In /etc/apache2/sites-available/, create a number of files like the following.  
It's conventional to name them after the websites to which they refer.  

#  /etc/apache2/sites-available/freds-shed.org.uk
<VirtualHost freds-shed.org.uk:80>
    ServerAdmin webmaster@freds-shed.org.uk
    ServerName www.freds-shed.org.uk
    DocumentRoot /home/fred/public_html/
    CustomLog /home/fred/logs/access.log combined
    ScriptAlias /cgi-bin/ "/home/fred/cgi-bin/"
    ScriptAlias /cgi-shared/ "/usr/lib/cgi-bin/"
    RewriteEngine on
    RewriteRule /([a-z0-9_-]*)\.aspx?$ /main.php?inc=$1 [PT]
</VirtualHost>
# same again without the www
<VirtualHost freds-shed.org.uk:80>
    ServerAdmin webmaster@freds-shed.org.uk
    ServerName freds-shed.org.uk
    DocumentRoot /home/fred/public_html/
    CustomLog /home/fred/logs/access.log combined
    ScriptAlias /cgi-bin/ "/home/fred/cgi-bin/"
    ScriptAlias /cgi-shared/ "/usr/lib/cgi-bin/"
    RewriteEngine on
    RewriteRule /([a-z0-9_-]*)\.aspx?$ /main.php?inc=$1 [PT]
</VirtualHost>

Then run
# a2ensite freds-shed.org.uk
to create a symlink at /etc/apache2/sites-enabled/freds-shed.org.uk
# apache2ctl graceful
to reload the server configuration
and it should work!

This example is a bit convoluted -- as a bare minimum, you can get away with 
just ServerName and DocumentRoot declarations.  It's always best to get the 
basics working before you put in the bells and whistles.  Then, you know the 
last thing you changed was what broke it.

Note that you have to have valid entries somewhere in DNS for every named 
virtualhost that is enabled; otherwise Apache starts up  v..e..r..y 
s..l..o..w..l..y  (but does run in the end).

-- 
AJS
delta echo bravo six four at earthshod dot co dot uk


Reply to: