1

First a quick disclaimer, I'm not a 'server guy' or a 'unix pro' or anything like that, I'm a web programmer who got stuck doing server works since I ran linux (ubuntu) on my netbook.

I'm trying to set up an apache server running on Debian to automagically serve multiple domains, each domain needs to have its own directory in /var/www.

Since this is the last thing I do for this company I really need it to be easy for my successor (who is even more a beginner at servers than I am), to create more domains without having to muck around with ssh or /etc/apache2/sites-available, so what I'm looking for is basically any magic mumbo-jumbo in default (or apt-get, or conf.d) that makes the server start serving any domain that has a matching folder in /var/www they will ofcourse have to initiate domain transfers the usual way.

I have no problem setting up domains individually.

Ick... hope the above makes sense to someone.

Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46

2 Answers2

1

To serve multiple domains from Apache, you'll need Apache Virtual Hosts. You can start serving any domain that has a matching folder in /var/www" with Apache Virtual Hosts using mod_vhost_alias.

The following configuration will take the fully-qualified domain name (like www.example.org) and use it as the variable '%0'. So, to serve out 'www.example.org', you create a directory at /var/www/www.example.org/docs , and place your HTML content there. Your Cgi script will go in /var/www/www.example.org/cgi-bin/

<VirtualHost 192.168.1.100:80>

# get the server name from the Host: header
UseCanonicalName Off

VirtualDocumentRoot /var/www/%0/docs
VirtualScriptAlias /var/www/%0/cgi-bin

</VirtualHost>

Then, point 'www.example.org' to '192.168.1.100', and Apache will happily serve that Virtual Host.

Stefan Lasiewski
  • 17,380
  • 5
  • 28
  • 35
  • what about a client enter 'http://example.org'? Will the url take him to the /var/www.example.org/docs directory? – cache Jun 27 '12 at 06:14
  • 1
    @cache : Good question. No, 'example.org' would take him to /var/**example.org**/docs not /var/www.example.org/docs . I am not sure what to do in this case, but I think the solution would involve some rewrites to send everything to a canonical URL beforehand. I think you should ask your question as a new question on Serverfault.com. I'd love to see how other people handle this. – Stefan Lasiewski Jun 27 '12 at 19:12
0

Untested Code with flavor of Ubuntu

sudo a2enmod rewrite
vi /etc/apache/sites-enabled/000-default

NameVirtualHost *
<VirtualHost *>
        DocumentRoot /var/www/
        RewriteEngine On
        RewriteRule ^(.*)$ %{HTTP_HOST}/$1
</VirtualHost>


sudo /etc/inid.d/apache2 restart
Mr. Ronald
  • 687
  • 4
  • 13