-1

I have multiple projects which I would like to server using an Apache VirtualDocumentRoot setup using Apache's mod_vhost_alias module such that each project has it's own domain name. As an example:

  • http://site1.local resides in /Users/stu/Sites/Project1/site1_app/
  • http://prox.local resides in /Users/stu/Sites/AlphaProX/prox_app/

I have about 20 entries like this and I was curious to know if I can have this setup. I currently have this VirtualHost entry that is not working:

<Virtualhost *:80>
    VirtualDocumentRoot "/Users/stu/Sites/*/%1/"
    ServerName vhosts.local
    ServerAlias *.local
    UseCanonicalName Off
    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    ErrorLog "/private/var/log/apache2/vhosts-error_log"
    <Directory "/Users/stu/Sites/*">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</Virtualhost>

Where is my syntax wrong?

5
  • 1
    @AngelS.Moreno The question may be on topic for Server Fault, but it is at best ambiguous. You seem to want something, but you do a poor job describing what you want. If you take some time to improve your question to meet our quality standards it may get reopened. Remember, we no nothing except what you tell us...
    – voretaq7
    Aug 28, 2013 at 15:38
  • 1
    thank you for the advice. I took it. please review the question now. Aug 28, 2013 at 20:01
  • 1
    If I didn't change your question with my edits, the answer is "You can't, because of the Project1 directory"
    – Josh
    Aug 28, 2013 at 21:08
  • Brilliant answer. symlinking is the way to get what i want! Aug 29, 2013 at 8:14
  • Glad I could help!
    – Josh
    Aug 29, 2013 at 14:51

1 Answer 1

2

No, as it is you can't do this because there is no way for Apache to determine the Project1 or AlphaProX part of the path name.

These strings must either be in the URL, or, they must not be in the path. It would work if the paths were like /Users/stu/Sites/prox/prox_app/ because now the variable string prox is used. But otherwise Apache has no idea to look under AlphaProX/, your VirtualDocumentRoot "/Users/stu/Sites/* line won't work. (Apache is literally looking for a directory named */)

You can make this work if you create a directory like /Users/stu/Sites/vhost_aliases and create symbolic links under that directory to the actual projects, EG:

mkdir -p /Users/stu/Sites/vhost_aliases
cd /Users/stu/Sites/vhost_aliases
ln -s ../site1_app
ln -s ../AlphaProX/prox_app

Then, you'll want your httpd.conf file to look like:

<Virtualhost *:80>
    VirtualDocumentRoot "/Users/stu/Sites/vhost_aliases/%1_app/"
    ServerName vhosts.local
    ServerAlias *.local
    UseCanonicalName Off
    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    ErrorLog "/private/var/log/apache2/vhosts-error_log"
    <Directory "/Users/stu/Sites/vhost_aliases">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</Virtualhost>

Specifically, this line:

VirtualDocumentRoot "/Users/stu/Sites/vhost_aliases/%1_app/"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .