Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run 2 websites with different domains from a single Azure VM

I have a Windows Azure VM which is on the Azure-provided domain myserver.cloudapp.net

On this VM I'm running two separate webapps on a single Tomcat instance, bob and fred. I've set it up so they are accessible on myserver.cloudapp.net/bob and myserver.cloudapp.net/fred respectively.

However, I don't want the user to be aware these sites are running under different contexts on the same server. I have two domains registered, www.bob.com and www.fred.com that I want to use for each individual site instead.

This is where I'm coming unstuck - I can find plenty of resources on how to map a single custom domain to a single Azure VM domain, but google as I might I can't find anything on how to map one or more custom domains to particular contexts under a single Azure domain.

I'm pretty new to webserver and DNS configuration etc, so I'm not even too sure on what level I should be looking to do this kind of mapping. Perhaps it's something I can do with rewrites on the VM itself, or perhaps it's better to do it in the DNS settings of my custom domains. I'm basically learning as I go with this stuff, so any pointers, tricks, hints, or links to tutorials so I can get further with this would be most appreciated.

Of course, I could just go the 'dumb' way and pay for two Azure VMs but these websites won't require much grunt to run and that just feels like admitting failure ;-)

like image 791
davnicwil Avatar asked Jan 05 '14 16:01

davnicwil


1 Answers

Ok so after a few hours of playing around I've got this to work.

My solution is to point both my custom domains to the Azure VM domain by configuring CNAME in the DNS settings for each of www.bob.com and www.fred.com to be myserver.cloudapp.net.

Then, on my Azure VM I use IIS URL rewrites to route http requests to the appropriate context on my local Tomcat instance - I can do this by looking at the host name in the request headers and choosing the correct internal url (with the correct app context /bob or /fred) based on that.

There's a whole load of other quirks specific to my applications that I had to wrestle with - setting this all up from scratch with no prior experience with IIS was no walk in the park - but if anyone else has this problem I'd recommend first checking out this very useful article which contains enough info to get going with a solution similar to the one I've gone with.

Amazing how you always find the best howtos when you already have a solution in mind and know exactly what to google for :-)

like image 198
davnicwil Avatar answered Sep 22 '22 04:09

davnicwil