在這個例子中域已經被替換爲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的證書「此頁面不安全,您確定要進行操作嗎?」
獎金回答:沒有。 –
nginx總是選擇一個服務器來回應請求。如果它不能匹配'server_name',它將爲'port'選擇_default_(通常是第一個)服務器塊。 –
http://nginx.org/en/docs/http/request_processing.html –