VirtualDocumentRoot域和子域

时间:2014-01-31 11:05:01

标签: apache

是否可以将VirtualDocumentRoot用于普通域和子域?

http://www.example.com/ or http://example.com

用途:

/var/www/example.com/

http://*.example.com

用途

/var/www/example.com/subdomains/*

到目前为止我所拥有的: Pastebin - VirtualDocumentRoot Domains and Subdomains

除了子域之外,普通域工作,显然它总是重定向到普通域。我使用的这些信息来自Stackoverflow - Apache-multiple-virtualdocumentroot

# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName domain.com
    ServerAlias www.domain.com domain.com
    VirtualDocumentRoot /var/www/%-2.0.%-1/web

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    ErrorLog /var/log/apache2/vhosts-error.log
    CustomLog /var/log/apache2/vhosts-access.log combined

    ServerSignature On
</VirtualHost>
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *.domain.com
    VirtualDocumentRoot /var/www/%-2.0.%-1/subdomains/%-3
</VirtualHost>

更新v2 [为我工作,直到现在才忽略子域名。]

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com example.com
    Options Indexes FollowSymLinks

    VirtualDocumentRoot /var/www/%-2_%-1/web/

    <Directory />
            AllowOverride none
    </Directory>

    <Directory "/var/www/*/web/">
        RewriteEngine on
        RewriteBase /
        # If a directory or a file exists, use it directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward it to index.php
        RewriteRule . index.php [L]


        <Files sitemap.xml>
            RewriteEngine Off
        </Files>
    </Directory>


        LogLevel debug
        ErrorLog /var/log/apache2/vhosts-error.log
        CustomLog /var/log/apache2/vhosts-access.log combined
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

您可以在服务器上为每个域和/或子域指定一个文件夹:) 有关样本,请参阅http://httpd.apache.org/docs/current/vhosts/examples.html

如果您遇到子域或域的问题,请检查您的DNS记录,看看您的域是否启用了子域。否则,在您的子域或* .doamin.com等别名中添加“A”记录 基本上,它的作用是将子域指向您的服务器IP地址。

查看此文章以获取DNS的简单指南:https://support.google.com/a/answer/48090?hl=en