批量虚拟主机 (Vhost.conf) 中的问题

批量虚拟主机 (Vhost.conf) 中的问题

很抱歉再次询问,但是我对这个问题有不同的看法。

/var/www/vhosts/domain.com/conf/vhost.conf想自动将子域名路由到它们自己的 DocumentRoot,我想知道我是否可以使用这种设置

我使用关键字DYNAMIC_SUB来表示将自动生成的域。

我不知道如何创建 vhost.conf 条目来执行我想要的操作,所以我从指向domain.com我的服务器和相关目录的现有条目中获取此模板,我对其进行了修改以显示我所寻找的内容。我知道有些人在看它时可能会笑 ;-) 但这是一种学习经历,我们都曾在这里度过。

我正在尝试让用户创建帐户并为他们提供自己的子域名而不是通常的 url 段。

所以test.domain.com而不是domain.com/test

我使用适用于 Linux 的 Plesk 10,而 Plesk API 在创建子域名方面很糟糕,因此我认为创建自己的子域名会更好,我只需要它作为参考点,以便用户可以存储小文件,同时仍然可以使用一些 PHP 技巧从主目录提供 index.php 文件。

是的,长话短说,我试图让 http://www.test.domain.com AND http://test.domain.com所有内容都指向它们自己的子域文件夹,同时仍然http://www.domain.com OR http://domain.com指向 Web 根目录。

我的区域文件中有一个 DNS 记录

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  "[email protected]"

        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>

答案1

我建议使用VirtualDocumentRoot指令(您也需要一个NameVirtualHost指令)。我重新格式化了您发布的配置文件,以便它更易读(尽量保持标签一致!):

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin [email protected]
    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 [email protected]
    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>

相关内容