#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    391
    Rep Power
    18

    Dynamic virtual host and sub domains


    I have been trying to set up a web server with dynamic virtual hosting and dynamic sub domains, but I've hit the wall.

    This is what I'm trying to accomplish, is it possible?

    Domain 1
    www.example.com => /folder/to/vhosts/example.com/web/www
    example.com => /folder/to/vhosts/example.com/web/www
    sub.example.com => /folder/to/vhosts/example.com/web/sub

    Domain N
    www.another.domain.co.uk => /folder/to/vhosts/another.domain.co.uk/web/www
    another.domain.co.uk => /folder/to/vhosts/another.domain.co.uk/web/www
    sub.another.domain.co.uk => /folder/to/vhosts/another.domain.co.uk/web/sub

    Please note that the goal is to not have a <VirtualHost> for every domain
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    391
    Rep Power
    18
    Okay, so I'm trying something else without any luck. Maybe this will spark some conversation. I'm trying to use the %{some_number} variables like one would use in the VirtualDocumentRoot, but like I said no such luck. If anyone has anything to add I would appreciate it.


    Code:
    <Macro VHost $sub $host>
        VirtualDocumentRoot /var/www/vhosts/$host/htdocs/$sub
        php_value open_basedir /var/www/vhosts/$host
        <Directory /var/www/vhosts/$host>
            AllowOverride all
            Require all granted
        </Directory>
    </Macro>
    
    <VirtualHost *:80>
    Use Vhost %1 %2+
    </VirtualHost>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    829
    Rep Power
    275
    If my reading is correct, this should give you what you need
    Code:
    UseCanonicalName Off
    VirtualDocumentRoot /folder/to/vhosts/%2+/web/%1
    [the only issue is with someone just using the domain without the "www".....so, you need a way to rewrite "domain.com" to "www.domain.com" before the vhost kicks in]

    the %2+ will look for everything after the subdomain and the %1 will satisfy just the subdomain.

    You will need to have the mod_vhost_alias module enabled.
    Last edited by DonR; August 24th, 2013 at 03:35 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    391
    Rep Power
    18
    Thanks for the input DonR

    I didn't even state my actual issue

    I was really trying to get the open_basedir to use the virtual host variables, but looks like that is impossible.

    I was hoping that by using mod_macro the variables would be viewed differently for the php_value syntax. But, the content of the variables passed to mod_macro are the literal strings not the virtual variables I was hoping for.

    With this set up I can only restrict php file includes to /var/www/vhosts, and all domains will be able to include files from other domains. This sucks! looks like I will need to write a conf file for every domain.


    As for the www prefix issue. After entering my first comment I tried looking for better ways of dealing with virtual hosting. After quite a bit of research I decided to use Nginx as the primary server and front end proxy for Apache. So, the redirect happens with Nginx's conf file.
    Last edited by aconway; August 24th, 2013 at 04:37 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    829
    Rep Power
    275
    hehe.....yea, it helps if you state your actual problem

    glad you somewhat found a way around your issue , tho.

IMN logo majestic logo threadwatch logo seochat tools logo