Is it possible to setup multiple Virtual Hosts with one ip/domain?
We have a single domain (example.com) pointing to our server at ip (123.123.555.555). At location 123.123.555.555 we require the following folder structure:
# production level
/htdocs/www/prod/proj1/
/htdocs/www/prod/proj2/
# dev level
/htdocs/www/dev/proj3/
/htdocs/www/dev/proj4
Where ideally we would like example.com
to resolve to /htdocs/www/prod/
and example.com/dev
to resolve to /htdocs/www/dev/
.
Simple enough no?
Caveats:
dev
andprod
need different setup directory/apache rules (allow deny from
, etc)prod
needs to resolve withoutprod
in the url.example.com/proj1
would gotoexample.com/prod/proj1
Attempts so far..
I've tried setting up with the same virtual host, but giving a directory an alias of /
sends it into a fit, claiming that it will be overwritten later. It makes sense because /
matches /
but also /dev
I've also tried setting up multiple virtual hosts with apache2' sites-available/sites-enabled but it seems I can't distinguish it based on the ip/domain. Normally I would attempt something like <Directory 'sub.domain.com'>
and <Directory 'sub2.domain.com'>
Best Answer
You have at least two options:
Setup a virtualhost for a subdomain of example.com and direct it to your dev folder. Here's an example of a .conf file to put in sites-available:
Setup virtualhost for a different port, i.e. 8080 or whatever you choose, and point this to the dev folder.