2016-09-30 71 views
0

我們有2個域指向相同的公共AWS ELB,在ELB後面我們有nginx,它會將請求重定向到正確的服務器。opennssl s_client顯示錯誤的證書:瀏覽器顯示正確

當我們打sub.domainA.com在瀏覽器(Chrome/Safari瀏覽器/等),一切正常,但是當我們使用的工具,如OpenSSL的,我們得到一個證書錯誤:

openssl s_client -host sub.domainA.com -port 443 -prexit -showcerts 

CONNECTED(00000003) 
depth=0 /OU=Domain Control Validated/CN=*.domainB.com 
verify error:num=20:unable to get local issuer certificate 
verify return:1 

出於某種原因,domainA正在使用domainB證書,我不知道爲什麼。

我幾乎可以100%肯定的問題是與我們的nginx的配置(更具體地說,不是有一個默認的服務器塊)

這裏是我們的nginx的配置:

worker_processes auto; 

error_log /var/log/nginx/error.log; 
error_log /var/log/nginx/error.log warn; 
error_log /var/log/nginx/error.log notice; 
error_log /var/log/nginx/error.log info; 

events { 
    worker_connections 1024; 
} 

http { 
    include  /usr/local/openresty/nginx/conf/mime.types; 
    default_type application/octet-stream; 
... 
    # 
    # DomainB 
    # 

    server { 
     ssl on; 
     ssl_certificate /etc/nginx/domainB.crt; 
     ssl_certificate_key /etc/nginx/domainB.key; 

     listen 8080; 

     server_name *.domainB.com; 

     access_log /var/log/nginx/access.log logstash_json; 

     error_page 497 301 =200 https://$host$request_uri; 

     set $target_web "web.domainB_internal.com:80"; 
     location/{ 
      keepalive_timeout 180; 
      resolver 10.10.0.2 valid=30s; 
      proxy_set_header Host $host; 
      proxy_pass http://$target_web; 
      proxy_set_header X-Unique-ID $request_id; 
     } 
    } 

    # 
    # DomainA 
    # 
    server { 
     ssl on; 
     ssl_certificate /etc/nginx/domainA.crt; 
     ssl_certificate_key /etc/nginx/domainA.key; 


     listen 8080; 
     server_name *.domainA.com; 

     access_log /var/log/nginx/access.log logstash_json; 

     error_page 497 301 =200 https://$host$request_uri; 

     set $target_web "web.domainA_internal.com:80"; 

     location/{ 
      keepalive_timeout 180; 
      resolver 10.10.0.2 valid=30s; 
      proxy_set_header Host $host; 
      proxy_pass http://$target_web; 
      proxy_set_header X-Unique-ID $request_id; 
     } 
    } 
} 

它不該」甚至不會落入domainB塊! 但我們在使用「openssl s_client」時會看到它,但在瀏覽器中不會。

任何想法爲什麼我們在使用「openssl s_client -host sub.domainA.com」時看到domainB?

非常相似,Openssl shows a different server certificate while browser shows correctly

非常有用的網站:https://tech.mendix.com/linux/2014/10/29/nginx-certs-sni/

回答

1

你需要指定你的openssl命令的servername選項。

openssl s_client文檔:

-servername name

Set the TLS SNI (Server Name Indication) extension in the ClientHello message.

所以嘗試像

openssl s_client -connect sub.domainA.com:443 -showcerts -servername sub.domainA.com 
+0

的問題是在nginx的,而不是被擊中HTTPS端點的工具。例如,它在openssl s_client上失敗,一些不轉發servername的瀏覽器,一些像嘗試命中端點的newrelic這樣的服務等等。我可以使用servname運行openssl s_client,但其他所有內容呢? – grayaii

+0

如果客戶端未指定SNI名稱作爲SSL握手的一部分,nginx應該如何知道要顯示哪個證書?客戶端的工作是在SSL握手本身中指定要連接到的主機,因爲主機頭將在稍後作爲HTTP請求的一部分發送。 – Rahul

+0

好問題,@Rahul!這是我的猜測:因爲openssl s_client適用於一個域而不適用於其他域(即失敗:「openssl s_client -host sub.domainA.com -port 443 -prexit -showcerts」):「openssl s_client -host sub.domainB.com -port 443 -prexit -showcerts「,我猜測nginx正在使用在配置中的FIRST服務器塊(這是domainB)中定義的證書。我仍在學習nginx,但不應該知道nginx服務器塊根據請求使用?我迫不及待地想出來! – grayaii

相關問題