2013-03-02 127 views
0

我在运行ubuntu 12.04的服务器中设置了一个网页。使用apache2和虚拟主机的子域配置

我已经停用了默认网站(a2dissite default default-ssl),并且我已经创建了一个新的,我需要和工作的那个将是一个子域。

想象我有foo.com。 我的目标是,foo.com抛出一个403 HTTP错误和sub.foo.com呈现网页,我需要。 我的虚拟主机是这个样子:

foo.com(默认)

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName foo.com 

    DocumentRoot /var/www/default 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
    </Directory> 
    <Directory /var/www/default/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     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 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

sub.foo.com

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName sub.foo.com 

    DocumentRoot /var/www/sub 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride All 
    </Directory> 
    <Directory /var/www/sub/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     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 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

当我访问sub.foo.com显示页面。 当我访问foo.com时,同一页面显示(:S),我需要在这里403 ...

我在做什么错?

回答

0

是否启用在你的Apache配置NamedVirtualHosts?阿帕奇是否给你任何警告重新启动时?所有启用的网站?

它们配置了不同的DocumentRoots,所以我猜你在两个路径中都有相同的文件,或者实际上有两个请求由相同的vhost配置提供服务。 在配置为foo.com我将开始通过改变Allow from allDeny from all

<Directory /var/www/default/> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride None 
    Order allow,deny 
    Deny from all 
</Directory> 

...您已经具备与变化的403所迎来了更大的机会;)