logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Question about dynamic vhosts, virtualdocumentroot
Author
neophitus



Joined: 05 Jun 2012
Posts: 3
Location: Brazil

PostPosted: Tue 05 Jun '12 16:58    Post subject: Question about dynamic vhosts, virtualdocumentroot Reply with quote

Hi guys!

First of all, this is a great place! A lot of infos about apache configuration!

Well, lets talk about my issue:
I've been running apache2 on Mac OS X (10.6.Cool. My Apache version is:
Server version: Apache/2.2.21 (Unix)
Server built: Dec 5 2011 20:56:38

I have a v-host setup, where i put my files like this:

/Work/www/<domai_name>/public, like example: /Work/www/www.google.com/public.
So, i set a wildcard subdomain on my main domain (*.dev.maindomain.com), and i can work like this:

/Work/www/test.dev.maindomain.com/public
/Work/www/wordpress.dev.maindomain.com/public
and etc...

so when i open http://test.dev.maindomain.com/ at my browser, its give me the website at /Work/www/test.dev.maindomain.com/public. This setup is working great.

But now, im starting to dev some rails applications, and i want it on a new folder on filesystem, like:

/Work/rails/test.rails.maindomain.com/public and so, when i open the address http://test.rails.maindomain.com i got to the webapp located at /Work/rails/test.rails.maindomain.com/public.

My DNS settings are working great, and my http-vhost.conf files is:

Code:


NameVirtualHost *:80
UseCanonicalName Off

<VirtualHost *:80>
        <Directory "/Projetos/www">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        VirtualDocumentRoot /Projetos/www/%0/public
</VirtualHost>

<VirtualHost *:80>
        <Directory "/Projetos/rails">
                AllowOverride All
                Options -MultiViews
        </Directory>
        VirtualDocumentRoot /Projetos/rails/%0/public
</VirtualHost>


The first VirtualHost is working as intended, but when i try to get the second vhost i got this error on my log:

Code:

[Tue Jun 05 11:52:43 2012] [error] [client 192.168.254.2] File does not exist: /Projetos/www/test.rails.empresalivre.com.br


As you guys can see, Apache is not giving me the /Projetos/rails/<project> like i need, and giving me the first directory from first Virtual Host!

Can someone give me some tips about this configuration?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 05 Jun '12 20:00    Post subject: Reply with quote

How is Apache supposed to know which one to go to, projects/www vs. project/rails? If there was an

<If "%{HTTP_HOST} =~ /rails/">
rails vhost container here
<Else>
www vhost container here
</If>

you could separate them that way, but there isn't this option in 2.2.x, only 2.4
Back to top
neophitus



Joined: 05 Jun 2012
Posts: 3
Location: Brazil

PostPosted: Tue 05 Jun '12 20:15    Post subject: Reply with quote

glsmith, with mod_vhost i can give apache a VirtualDocumentRoot, to each VirtualHost, as i show on my vhost.conf.
I figured out how to do that: all i need was the ServerAlias directive.

Code:

NameVirtualHost *:80

<VirtualHost *:80>
        ServerAlias *.dev.empresalivre.com.br <-- This Line Solved My Issue
        UseCanonicalName Off
        <Directory "/Projetos/www">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        VirtualDocumentRoot /Projetos/www/%0/public <-- This Line shows where to get files from
</VirtualHost>

<VirtualHost *:80>
        ServerAlias *.rails.empresalivre.com.br
        UseCanonicalName Off
        <Directory "/Projetos/rails">
                AllowOverride All
                Options -MultiViews
                Order allow,deny
                Allow from all
        </Directory>
        VirtualDocumentRoot /Projetos/rails/%0/public
</VirtualHost>


Thx to all! Now everything is working as intended!
Back to top
admin
Site Admin


Joined: 15 Oct 2005
Posts: 692

PostPosted: Tue 05 Jun '12 20:49    Post subject: Reply with quote

I missed Servername directive in your config.

Always learning, thanks, I learned now how to use virtualdocumentroot .

http://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html#virtualdocumentroot

Steffen
Back to top
neophitus



Joined: 05 Jun 2012
Posts: 3
Location: Brazil

PostPosted: Tue 05 Jun '12 20:53    Post subject: Reply with quote

ServerName directive does not work on this case. Here we need to use ServerAlias instead. I'm glad to show all my solution Smile
Back to top
Millennium



Joined: 17 Apr 2006
Posts: 179
Location: Leiderdorp, NL, EU

PostPosted: Tue 05 Jun '12 21:54    Post subject: Reply with quote

Well the first virtualhost is always catch all.

The second needs some ServerName and/or ServerAlias to be used instead of the catch all.

I always use

ServerName domain.com (to match http://domain.com)
ServerAlias *.domain.com (to match all subdomains of domain.com)
Back to top


Reply to topic   Topic: Question about dynamic vhosts, virtualdocumentroot View previous topic :: View next topic
Post new topic   Forum Index -> Apache