2015-12-18 22 views
0

在這個例子中域已經被替換爲domain.comNginx的服務器名和收聽比賽指定模式

我們的主要問題: 當我輸入https://domain.com我不重定向到https://www.domain.com,我們目前還沒有這是一個規則什麼是解決這個問題的最好方法?

根據我們的nginx配置,我們還沒有爲https://domain.com指定443,但仍然可以訪問,爲什麼?

我們對domain.com和www.domain.com都有有效的ssl證書。 我們沒有通配符證書* .domain.com。

我們的配置:

#All non-matching patterns 
server 
{ 
    listen 80; 

    #enabling this will cause things to break. 
    #2015/12/18 09:21:54 [error] 32165#0: *1661 no "ssl_certificate" is defined in server listening on SSL port while SSL handshaking, client: *censored*, server: 0.0.0.0:443 
    #listen 443 ssl; 

    #Horrible looking match all pattern. 
    server_name _ "" domain.com *.domain.com; 

    return 301 https://www.domain.com$request_uri; 
} 

#Main site ssl enforced 
server 
{ 
    listen 443 ssl; 

    server_name www.domain.com ios.domain.com android.domain.com; 

    ... 
} 

#Staging/Test site 
server 
{ 
    listen 443 ssl; 
    listen 80; 

    server_name stage.domain.com; 

    ... 
} 

#Rental cars site ssl enforced 
server 
{ 
    listen 443 ssl; 

    server_name hyrbil.domain.com; 

    ... 
} 

#ios redirect to enforce https 
server 
{ 
    listen 80; 

    server_name ios.domain.com; 

    return 301 https://ios.domain.com$request_uri; 
} 

#android redirect to enforce https 
server 
{ 
    listen 80; 

    server_name android.domain.com; 

    return 301 https://android.domain.com$request_uri; 
} 

獎金的問題: 是否可以匹配所有的SSL流量,做一個重定向,除非它特定的域相匹配,例如使https://xxx.domain.com傳遞301到https://www.domain.com甚至儘管我不沒有顯示xxx.domain.com的證書「此頁面不安全,您確定要進行操作嗎?」

+0

獎金回答:沒有。 –

+0

nginx總是選擇一個服務器來回應請求。如果它不能匹配'server_name',它將爲'port'選擇_default_(通常是第一個)服務器塊。 –

+0

http://nginx.org/en/docs/http/request_processing.html –

回答

0

如果您有一個虛擬主機在443上進行偵聽,則所有流量將達到您的IP地址將由該虛擬主機提供服務。

爲domain.com創建一個SSL虛擬主機,並在其中添加一個簡單的重定向。

或者創建一個「一網打盡/默認的」 SSL虛擬主機,並檢查HOST頭和重定向有關,像:在所有的FQDN

if ($host !~* ^www\.doman\.com$) { rewrite ^(.*)$ http://www.domain.com$1 permanent; } 但它會顯示SSL證書錯誤不包括您的證書了!