Setting Up Domains in Apache

Share via Twitter Share via Facebook Share via Linkedin Share via Reddit

Just a quick note on some Apache stuff I figured out last night. Those of you who either aren’t technical or aren’t likely to be near Apache might want to skip this one. Ditto for the folks that already know Apache well. Moving along…

The problem I was trying to solve was actually fairly simple. We at RedMonk have multiple domains: redmonk.com, red-monk.com, monkchips.com, peopleoverprocess.com, tecosystems.org and so on. When we were running on top of a managed server, setting up new domains was the province of the managed server interface. Point this domain to this directory, and done.

On our coloed box, however, all the above domains know to do is resolve to our machine. So since our switch, monkchips.com and tecosystems.org, specifically, have been resolving to the basic redmonk.com rather than redmonk.com/jgovernor and redmonk.com/sogrady respectively. With me so far?

In essence, our problem was one of redirection. I needed to redirect incoming requests to another subdirectory on our machine. Seemed pretty simple, particularly because I have some experience with that in the form of Apache .htaccess files. A couple of quick searches led me to conclude that a .htaccess file placed in the root of our webserver that contained the following:

Redirect 301 http://www.tecosystems.org /sogrady

Should turn the redirection trick nicely. You Apache folks in the back of the room snickering at me, pipe down – I’m a confessed Apache noob.

After trying this, I was immediately presented with a very basic problem in that it didn’t work. As in, nothing happened. tecosystems.org continued resolving to redmonk.com as if the .htaccess wasn’t even there.

Back to the forums I went, and I discovered that my .htaccess file was not active for a simple reason: the default Ubuntu Apache config turns it off. The config for an Apache server in Ubuntu reads:

Options FollowSymLinks
AllowOverride None

I’ve bolded the ‘None’ because that was the problem. The none tells Apache that nothing – .htaccess files included – can override the standard configuration. It ignores the .htaccess file, in other words. So that was relatively easily remedied by changing AllowOverride None to AllowOverride All. Patting myself on the back for being so terribly clever, I hopped on a browser, headed to redmonk.com and was presented with an HTTP 500. That’s a problem.

After a bit of trial and error, I discovered that it was in fact the redirection line that was causing the problem. As soon as I removed that, everything was kool & the gang and resolving. Except for the fact, of course, that I still did not our vanity domains working properly.

More research led to the discovery of Apache’s virtual hosts facility. I was loathe to try this because my last experience with the functionality on a Solaris 10 box was while not technically classifiable as a disaster, not terribly fruitful either. But it seemed like the best option available to me.

On Dapper – the version of Ubuntu we’re running as our production server – the Apache file is split up, and the virtual hosts are located in a separate directory – /etc/apache2/sites-enabled, in our case. After looking at the default, and a couple of examples online, I thought that it didn’t look all that difficult, so I created a file (I’d display it, but don’t know how to escape everything in MT) called 001-tecosystems, dropped it in /etc/apache2/sites-enabled, and restarted Apache (/etc/init.d/apache2 restart). What does that do? Go hit www.tecosystems.org and see. As I’ve been told, Apache can be easy to configure – if you know how to do it.

Despite the success in getting the basic domain work done, there are still a couple of problems. The virtual host set up seems to break relative links; the blog templates, for example, were unable to find their CSS files until I provided them an absolute (http://www.redmonk…) path. Normally, this wouldn’t be a problem – as the CSS fix demonstrates – but as covered the other day, Dojo doesn’t like absolute paths so the tooltips over at sogrady.org have broken. Also, I have yet to get subdomains (wiki.redmonk.com) working via a virtual host. When I tried to set up one for the wiki, it loaded wiki.redmonk.com but appended index.php on a dozen or more times. So no joy on that score.

So overall, Apache’s not too difficult to work with. A little obscure and esoteric at times, but manageable. The real question is whether the above – as I’ve contended previously – seems like an opportunity, and if so, for whom? More on that later.


  1. You should stick a ServerAlias tecosystems.org to your 001-tecosystems file, which will make http://tecosystems.org/ work as well.

  2. bless you, james. worked like a champ. will do that for the other sites as well.

  3. Perfectly illustrates how much work needs to be done on usability in the Open Source world.

    My reverse proxy handles virtual hosting nicely. You create your websites as directories (http://ipaddr/sogrady) on Apache (no special configuration required except you might want to listen on The proxy then intercepts incoming public requests for virtual domains and proxies (not redirects which is technically different) them to the correct directory on Apache.

    For instance

    firefox requests http://monkchips.com/->
    proxyserver handles request and proxies to http://ipaddr/sogrady->
    Apache handles the final request

    This stuff is a nightmare to setup with apache.

  4. Why don’t you use webmin to set this all up ?

  5. I generally go about it as follows:

    NameVirtualHost *:80

    <VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://redmonk.com/sogrady/
    ProxyPassReverse / http://redmonk.com/sogrady/
    ServerName http://www.tecosystems.org

Leave a Reply

Your email address will not be published. Required fields are marked *