Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm sorry to ask this again, but I have a different variant of this question.

in my /var/www/vhosts/domain.com/conf/vhost.conf I want to automatically route subdomains to their own DocumentRoot and was wondering if I could use this type of set up

I used the keyword DYNAMIC_SUB to represent a domain that will be made automatically.

I have no idea how to make a vhost.conf entry to do what i want so I took this template from an already existing entry that points domain.com to my server and related directories, I modified it to show an idea of what I was looking for. I know some people might chuckle while looking at it ;-) but its a learning experience and we were all here at some point or another.

I'm trying to let users create accounts and to give them their own sub domain instead of the usual url segment.

so test.domain.com instead of domain.com/test

I use Plesk 10 for Linux, and the Plesk API is crap with making sub domains, so I figured making my own would be better, I just need it as a point of reference so a user can store small files while still being served the index.php files from the main directory using some PHP tricks.

Right, well to make long story short I'm trying to make http://www.test.domain.com AND http://test.domain.com all point to their own sub domain folder while still going to either http://www.domain.com OR http://domain.com will point to the web root.

I have a DNS record in my Zone File

domain.com     with an A record pointing to my HOST_IP

*.domain.com   with an A record pointing to my HOST_IP

www.domain.com with an A record pointing to my HOST_IP



<VirtualHost HOST_IP:80>
    ServerName "DYNAMIC_SUB.domain.com:80"
        ServerAlias  "DYNAMIC_SUB.domian.com"
        UseCanonicalName Off

<IfModule mod_suexec.c>
    SuexecUserGroup "USER_GROUP" "psacln"
</IfModule>

    ServerAdmin  "admin@domain.com"

        DocumentRoot "/var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB"
    CustomLog /var/www/vhosts/domain.com/statistics/logs/access_log plesklog
    ErrorLog  "/var/www/vhosts/domain.com/statistics/logs/error_log"



<IfModule mod_userdir.c>
    UserDir "/var/www/vhosts/domain.com/web_users"
</IfModule>

    ScriptAlias  "/cgi-bin/" "/var/www/vhosts/domain.com/users/DYNAMIC_SUB/cgi-bin/"



    Redirect permanent /plesk-stat https://domain.com/plesk-stat
    Redirect permanent /webstat https://domain.com/webstat
    Redirect permanent /webstat-ssl https://domain.com/webstat-ssl
    Redirect permanent /ftpstat https://domain.com/ftpstat
    Redirect permanent /anon_ftpstat https://domain.com/anon_ftpstat
    Redirect permanent /awstats-icon https://domain.com/awstats-icon


    <IfModule mod_ssl.c>
        SSLEngine off
    </IfModule>

    <Directory /var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB/>

<IfModule mod_perl.c>
    <Files ~ (\.pl$)>
        SetHandler perl-script
        PerlHandler ModPerl::Registry
        Options ExecCGI
        allow from all
        PerlSendHeader On
    </Files>
</IfModule>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir /var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB/:/tmp/
</IfModule>

<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir /var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB/:/tmp/
</IfModule>
<IfModule mod_python.c>
    <Files ~ (\.py$)>
        SetHandler python-program
        PythonHandler mod_python.cgihandler
    </Files>
</IfModule>
<IfModule mod_fcgid.c>
    <Files ~ (\.fcgi)>
        SetHandler fcgid-script
        Options +FollowSymLinks +ExecCGI
    </Files>
</IfModule>


        Options -Includes +ExecCGI

    </Directory>



Alias "/error_docs" "/var/www/vhosts/domain.com/error_docs"


    Include "/var/www/vhosts/domain.com/conf/vhost.conf"

</VirtualHost>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'd recommend using the VirtualDocumentRoot directive (you'll need a NameVirtualHost directive, too). I've reformatted the config file that you posted, so that it's a bit more readable (try to keep your tabs consistent!):

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin admin@domain.com
    CustomLog /var/www/vhosts/domain.com/statistics/logs/access_log plesklog
    ErrorLog  /var/www/vhosts/domain.com/statistics/logs/error_log
    DocumentRoot /var/www/vhosts/domain.com/httpdocs
    # You'll also need an SSL port listener for these to work.
    Redirect permanent /plesk-stat https://domain.com/plesk-stat
    Redirect permanent /webstat https://domain.com/webstat
    Redirect permanent /webstat-ssl https://domain.com/webstat-ssl
    Redirect permanent /ftpstat https://domain.com/ftpstat
    Redirect permanent /anon_ftpstat https://domain.com/anon_ftpstat
    Redirect permanent /awstats-icon https://domain.com/awstats-icon
    Alias /error_docs /var/www/vhosts/domain.com/error_docs
    # Commenting this out, since it's hopefully not doing anything...?
    #Include "/var/www/vhosts/domain.com/conf/vhost.conf"
</VirtualHost>

<VirtualHost *:80>
    ServerName dynamic.domain.com
    ServerAlias *.domain.com
    ServerAdmin admin@domain.com
    CustomLog /var/www/vhosts/domain.com/statistics/logs/access_log plesklog
    ErrorLog  /var/www/vhosts/domain.com/statistics/logs/error_log
    # This is telling it to use the third-to-last chunk of the name here,
    # the "test" in "test.domain.com" or "www.test.domain.com"
    # Note that "www.domain.com" will be caught in the static config above.
    VirtualDocumentRoot /var/www/vhosts/domain.com/httpdocs/users/%-3
</VirtualHost>

# We'll move this chunk out here, since it's applying
# to both configurations (static and dynamic)
<Directory /var/www/vhosts/domain.com/httpdocs/users/>
    # Drop these scripting languages if they aren't used.
    # I sure hope you don't want all of these running..
    <IfModule mod_perl.c>
        <Files ~ (\.pl$)>
            SetHandler perl-script
            PerlHandler ModPerl::Registry
            Options ExecCGI
            allow from all
            PerlSendHeader On
        </Files>
    </IfModule>
    <IfModule sapi_apache2.c>
        php_admin_flag engine on
        php_admin_flag safe_mode off
        # not sure how to make this work as desired
        #php_admin_value open_basedir /var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB/:/tmp/
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
        php_admin_flag safe_mode off
        # not sure how to make this work as desired
        #php_admin_value open_basedir /var/www/vhosts/domain.com/httpdocs/users/DYNAMIC_SUB/:/tmp/
    </IfModule>
    <IfModule mod_python.c>
        <Files ~ (\.py$)>
            SetHandler python-program
            PythonHandler mod_python.cgihandler
        </Files>
    </IfModule>
    <IfModule mod_fcgid.c>
        <Files ~ (\.fcgi)>
            SetHandler fcgid-script
            Options +FollowSymLinks +ExecCGI
        </Files>
    </IfModule>
    Options -Includes +ExecCGI
</Directory>
share|improve this answer
    
Hmmm, the tabs are as is in my vhost.vonf. I did a direct copy and paste just modified it here to explain what I was looking for. What I was wondering is that in the second <virtualhost> you listed dynamic.domain.com, is that significant? i need to leave it like that or is that just a dummy servername? –  s2xi May 13 '11 at 5:55
    
On the tabs, I'm saying that your file could use cleanup - what you provided was very hard to read. And no, the name there is just a dummy; the real work is done by the Alias and the VirtualDocumentRoot. –  Shane Madden May 13 '11 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.