How do I host multiple MVC3 sites on a single virtual host running Apache2? How do I host multiple MVC3 sites on a single virtual host running Apache2? apache apache

How do I host multiple MVC3 sites on a single virtual host running Apache2?


your problem is that your Alias name and physical path are one and the same, so apache doesn't know which one to serve up.

NOTE: I'm giving the answer based on general Apache2 configuration, and not on mod_mono, maybe mod_mono does something to prevent this, I've not set MVC apps up under a *nix box before :-)

Anyway...

if you look at your path configurations you have...

/Library/WebServer/vhosts/api/Library/WebServer/vhosts/api/gamecenter/Library/WebServer/vhosts/api/gamecenter-stage

without your aliases in place, these already resolve to the paths your trying to map.

/Library/WebServer/vhosts/api  = //Library/WebServer/vhosts/api/gamecenter  = /gamecenter/Library/WebServer/vhosts/api/gamecenter-stage  = /gamecenter-stage

Your then telling Apache that

/ = //gamecenter = /gamecenter/gamecenter-stage = /gamecenter-stage

When Apache tries to deliver the content if there is no file subfix or existing slash (as in the last 2) it will automatically, subfix the folder with a / then issue a redirect (306 I believe) essentially telling the browser to redirect from EG:

/gamecenter to /gamecenter/

With the alias in place to tell it that Alias ... is at location x it then has to try and make a desicion to serve

/gamecenter/

or

/gamecenter/gamecenter/../ (Because in terms of folder structure the alias name is 1 folder level down in the web than it is physically)

and ends up getting confused, and so does what any virtual host set up does when it's unable to resolve the path, and that's return the website root.

AS I SAY however, this is general NON-MONO Apache behaviour, it is possible that mod_mono may alter the processing pipeline in some way to that may change this behaviour.

What I would recommend is to split this into 3 virtual hosts which you can do very very easily even on just one IP.

First thing you'll want to do is somwhere in your master Apache config file, have a

Listen 9005

statement. This will make ALL virtual instances listen on that port as well as any other configured port EG: 80

Next make sure you have a default catch all virtual host, this will catch any server name not mapped elsewhere:

<VirtualHost *>  DocumentRoot "/some/folder/where/the/default/is/"  #Followed by other server directives. NOTE: there is NO servername line</VirtualHost>

Once you have that set up, then move onto your "api" sub domain

<VirtualHost *>  ServerName api  DocumentRoot "/Library/WebServer/vhosts/api/"  #Other required directives here</VirtualHost>

At this point, I'm going to pause to discuss your domain name. If this is an internal test system (Which I suspect it is) then you'll find life with virtual domains way easier if you install a DNS server on you box, then set that up as a master domain using a private internal network address.

EG:

Create a root zone, and call it "mydevnetwork.local"

then add machine names to it:

EG: if your pc is called devpc1, create an IP address for "devpc1.mydevnetwork.local" and give your pc a static IP address of EG: 192.168.50.1

Then set an alias for that so

api.mydevnetwork.local = devpc1.mydevnetwork.local

Iv'e not got the room to do a full DNS setup post here, but hopefully you get the idea.

Once you have DNS (or at a minimum host file entries) set up, then your virtual hosts under Apache become really easy to manage:

<VirtualHost *>  ServerName api.mydevnetwork.local  DocumentRoot "/Library/WebServer/vhosts/api/"  #Other required directives here</VirtualHost>

and easy to relocate to another machine should you need too.

You can set the rest of your virtual hosts up in much the same way

<VirtualHost *>  ServerName gamecenter.mydevnetwork.local  DocumentRoot "/Library/WebServer/vhosts/api/gamecenter/"  #Other required directives here</VirtualHost><VirtualHost *>  ServerName gamecenter-stage.mydevnetwork.local  DocumentRoot "/Library/WebServer/vhosts/api/gamecenter-stage/"  #Other required directives here</VirtualHost>

Note iv'e set the paths to be the same as you had above, and even though this will work, I'd strongly advise that you give each one it's own unique folder, I generally do something like:

wwwroot    api.mydevnetwork.local        htdocs   <-- Web files go here        cgi-bin  <-- cgi scripts go here and it's mapped to /cgi-bin/        logs     <-- logs here        access   <-- htpasswd files here

Hopefully if the above is not a complete solution, you might at least get some further ideas of investigation from it.