2013-03-02 128 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所迎來了更大的機會;)