具有相同域名的两个单独项目的虚拟主机

时间:2014-04-16 09:33:48

标签: virtualhost

我有两个项目。一个是主项目,另一个是单独的模块项目。我想为两个使用相同域和子目录结构配置虚拟主机。

例如:www.example.com指向一个主要项目,而www.example.com/submodule则是另一个独立项目。

我的两个虚拟主机

<VirtualHost *:80>
    ServerAdmin it@example.com

    DocumentRoot /var/www/mainproject/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    ServerName dev-test.example.com
    DirectoryIndex index.php
    <Directory /var/www/mainproject/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

子模块虚拟主机:

<VirtualHost *:80>
    ServerAdmin it@example.com

    DocumentRoot /var/www/example/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    ServerName dev-test.example.com
Alias /module /var/www/example/
    DirectoryIndex index.php
    <Directory /var/www/example/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

这有什么不对吗?

1 个答案:

答案 0 :(得分:0)

我合并为单个My virtual host file。我的代码:

<VirtualHost *:80>
    ServerAdmin it@example.com

    DocumentRoot /var/www/example/docroot
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    ServerName dev-test.example.com
    DirectoryIndex index.php
    <Directory /var/www/example/docroot/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
    Alias /module/ "/var/www/example2/"
    <Directory "/var/www/example2/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        DirectoryIndex index.php
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined