curl: how to specify target hostname for https request

后端 未结 2 1504
野的像风
野的像风 2020-12-31 12:43

I have a x.example which serves traffic for both a.example and b.example. x.example has certificates for both a.exa

2条回答
  •  醉梦人生
    2020-12-31 13:08

    The selected answer helped me find the answer, even though it does not contain the answer. The answer in the mail/archive link Patrick Mevzek provided has the wrong port number. So even following that answer will cause it to continue to fail.

    I used this container to run a debugging server to inspect the requests. I highly suggest anyone debugging this kind of issue do the same.

    Here is how to address the OP's question.

    # Instead of this:
    # curl --header 'Host: a.example'        https://x.example
    
    # Do:
      host=a.example
      target=x.example
    
      ip=$(dig +short $target | head -n1)
      curl -sv   --resolve $host:443:$ip https://$host
    
    

    If you want to ignore bad certificates matches, use -svk instead of -sv

    curl -svk --resolve $host:443:$ip https://$host
    

    Note: Since you are using https, you must use 443 in the --resolve argument instead of 80 as was stated on the mail/archive

提交回复
热议问题