2011-03-08 122 views
14

我希望有人能夠幫助我。我有兩個IP可用於執行此操作,並需要在同一臺Apache服務器上託管兩個不同的安全(SSL)域。我已經閱讀了Apache 2.2的某些東西,可以使用單個IP,使用某種插件,但我希望儘可能簡單,並且願意使用兩個IP來完成此任務。我已經擁有了兩個域的簽名證書。在apache上託管多個SSL證書

這是我在這裏發佈的設置,但是我遇到的問題是當我訪問domain2.net時,收到瀏覽器警告,告知我該證書與域不匹配,但與domain1.com匹配

我正在使用CentOS 5和Apache 2.2.3。 CentOS的擁有的ssl.conf文件,這些線是什麼,我相信是給我找麻煩:

SSLCertificateFile /etc/pki/tls/certs/domain1.com.crt 
SSLCertificateKeyFile /etc/pki/tls/private/domain1.com.key 

我是,我可以在虛擬主機容器覆蓋這些值並引用我需要的按鍵的印象,但它看起來並不那樣。當我在ssl.conf文件中註釋這兩行時,Apache不會重新啓動。該ssl_log提示:SSLCertificateKeyFile

這是我的虛擬容器:

<VirtualHost 2.2.2.2:443> 
    SSLEngine on 
    SSLCertificateFile /etc/pki/tls/certs/domain2.net.crt 
    SSLCertificateKeyFile /etc/pki/tls/private/domain2.net.key 

    DocumentRoot "/var/www/domain2" 
    ServerName domain2.net 
    ServerAlias domain2.net 
    DirectoryIndex "index.php" 

    <Directory /var/www/html/domain2> 
    Options -Indexes FollowSymLinks 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 


<VirtualHost 1.1.1.1:444> 
    SSLEngine on 
    SSLCertificateFile /etc/pki/tls/certs/domain1.com.crt 
    SSLCertificateKeyFile /etc/pki/tls/private/domain1.com.key 

    DocumentRoot "/var/www/html" 
    ServerName domain1.com 
    ServerAlias domain1.com 
    DirectoryIndex "index.php" 

    <Directory /var/www/html> 
    Options -Indexes FollowSymLinks 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

我怎樣才能得到這兩個領域使用SSL來工作?我也試着爲不同的IP使用相同的端口,但是Apache不會重新啓動。

我真的迷失了,所以如果有人能伸出援手,我會非常感激。

回答

10

偉大的問題!

我能夠獲得兩個SSL證書在同一臺服務器上工作。你應該能夠做你想做的事情。

在配置中脫穎而出奇給我的東西:

  1. 我建議使用443端口兩個SSL保護的網站。你應該在Apache中的conf特定指令的地方文件偵聽端口443對我來說,它位於/etc/apache2/ports.conf

    Listen 443 
    

  2. 你有ServerName和ServerAlias都使用每個虛擬主機相同的域,這似乎很奇怪。嘗試使ServerAlias不同或將其忽略:

    ServerName domain1.com 
    ServerAlias www.domain1.com 
    

  3. 我假設你在發佈的conf中替換了你的IP和域名。即使它們不是您使用的實際IP,也可能需要仔細檢查是否可以將您帶到SSL之外的正確位置(因爲顯然SSL不起作用)。

查看apache2錯誤日誌以獲取更多信息。對我來說,日誌位於:/var/log/apache2/error.log。您可以將其設置爲: ErrorLog/var/log/apache2/error。日誌

最後,爲了您的參考,這裏是我的ssl-default(ssl.conf)。我用您在示例conf中使用的域名和IP替換了我的域名和IP。我有多個子域與工作了NameVirtualHost,因爲我有一個通配符證書:

<IfModule mod_ssl.c> 
<Directory /> 
    Options FollowSymLinks 
    AllowOverride All 
</Directory> 
<Directory /var/www/> 
    Options FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 

NameVirtualHost 1.1.1.1:443 
NameVirtualHost 2.2.2.2:443 

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

<FilesMatch "\.(cgi|shtml|phtml|php)$"> 
    SSLOptions +StdEnvVars 
</FilesMatch> 

# 1.1.1.1 = domain1.com 

<VirtualHost 1.1.1.1:443> 
    ServerName www.domain1.com 

    ServerAdmin [email protected] 

    SSLEngine on 
    SSLCertificateKeyFile /var/www/ssl/domain1.key 
    SSLCertificateFile /var/www/ssl/wildcard.domain1.crt 

    BrowserMatch ".*MSIE.*" \ 
    nokeepalive ssl-unclean-shutdown \ 
    downgrade-1.0 force-response-1.0 

    DocumentRoot /var/www/domain1/www.domain1.com/web 
    DirectoryIndex index.php index.html 
</VirtualHost> 

<VirtualHost 1.1.1.1:443> 
    ServerName secure.domain1.com 

    ServerAdmin [email protected] 

    SSLEngine on 
    SSLCertificateKeyFile /var/www/ssl/domain1.key 
    SSLCertificateFile /var/www/ssl/wildcard.domain1.crt 

    BrowserMatch ".*MSIE.*" \ 
    nokeepalive ssl-unclean-shutdown \ 
    downgrade-1.0 force-response-1.0 

    DocumentRoot /var/www/domain1/secure.domain1.com/ 
    DirectoryIndex index.php index.html 
</VirtualHost> 


# 2.2.2.2 = *.domain2.com 

<VirtualHost 2.2.2.2:443> 
    ServerName admin.domain2.com 

    ServerAdmin [email protected] 

    SSLEngine on 
    SSLCertificateKeyFile /var/www/ssl/domain2.key 
    SSLCertificateFile /var/www/ssl/domain2.crt 

    BrowserMatch ".*MSIE.*" \ 
    nokeepalive ssl-unclean-shutdown \ 
    downgrade-1.0 force-response-1.0 

    LogLevel warn 
    CustomLog /var/log/apache2/access.log combined 
    ErrorLog /var/log/apache2/error.log 

    DocumentRoot /var/www/domain2/secure.domain2.com/web 
    DirectoryIndex index.php index.html 

    php_flag display_errors on 
    php_value error_reporting 7 
</VirtualHost> 

</IfModule> 

我希望這有助於!

+1

這幫了我很多!我也有Apache給出兩個虛擬主機相同的證書。將ServerName更改爲每個虛擬主機獨有的解決方案!只是想確認這是否適用於下一個搜索此人的人 – Christian 2013-05-26 16:14:33

0

您不需要單獨的ssl.config文件,但是如果您想使用其中一個,請將SSL <VirtualHost XXX:443>容器放在您的ssl.conf文件中,而不要放在您的httpd,conf文件中。

我們在我們網站上使用的另一個選項是將ssl.conf文件中的設置放在我們的httpd.conf文件中,並將ssl.conf文件重命名爲類似ssl.conf.bak的文件(以便保留它參考)。