2012-05-15 80 views
0

我有一個奇怪的問題,當我使用SSL設置虛擬主機時,我的虛擬主機不受限制。除了虛擬主機不僅限於名稱這一事實以外,一切都按預期工作。例如,如果我瀏覽到https://qa.example.com/,我就會得到正確的頁面。但是,如果我瀏覽到https://foo.example.com/,我可以享受同一頁面!我已經閱讀http://httpd.apache.org/docs/2.2/vhosts/name-based.html的基於命名的配置,所以我不知所措。虛擬主機不尊重ServerName屬性

這裏是我的/etc/apache2/sites-enabled/mysite-ssl文件(我使用Ubuntu 12.04):

<IfModule mod_ssl.c> 
<VirtualHost *:443> 
    <IfModule dir_module> 
      DirectoryIndex login.html 
    </IfModule> 
    ServerAdmin [email protected] 
    ServerName qa.example.com 
    DocumentRoot /var/www/example 

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

    JkMount /axonify/* worker1 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined 

    SSLEngine on 
    SSLCertificateFile "/etc/ssl/certs/star.example.com.crt" 
    SSLCertificateKeyFile "/etc/ssl/private/star.example.com.key" 
    BrowserMatch "MSIE [2-6]" \ 
      nokeepalive ssl-unclean-shutdown \ 
      downgrade-1.0 force-response-1.0 
    # MSIE 7 and newer should be able to use keepalive 
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown 
</VirtualHost> 
</IfModule> 

/etc/apache2/ports.conf文件是我定義了NameVirtualHost項:

NameVirtualHost *:80 
Listen 80 

<IfModule mod_ssl.c> 
    NameVirtualHost *:443 
    Listen 443 
</IfModule> 

<IfModule mod_gnutls.c> 
    NameVirtualHost *:443 
    Listen 443 
</IfModule> 

現在我/etc/apache2/sites-enabled/000-default文件也很簡單:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    RewriteEngine on 
    ReWriteCond %{SERVER_PORT} !^443$ 
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L] 
</VirtualHost> 

我做n沒有部署一個default-ssl站點,並且我只部署了一個啓用了SSL的站點。

+0

我已經解決了這個問題。似乎我需要default-ssl文件,該文件指定作爲任何不匹配虛擬主機的回退的''條目。 –

回答

0

我已經解決了這個問題。似乎我需要default-ssl文件,該文件指定<VirtualHost _default_:443>條目作爲任何不匹配的虛擬主機的回退。