title: SSL_CTX_use_PrivateKey_file("/example.key") failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch
body: <h3>Problem Statement:</h3>
  <p>I've wanted to change the SSL certificate, because I've changed my server so I had to create a new CSR with the different name as discuss in the following <a href="https://stackoverflow.com/a/42111969">question</a> with this command. And generated the <strong>Privatekey</strong> and <strong>CSR</strong>.</p>
  <pre><code>$ openssl req -new -newkey rsa:2048 -nodes -keyout example_new.key -out example_new.csr
  </code></pre>
  <p>Then I'd paste the CSR to <strong>Re-Key</strong> in Godaddy portal and received certificate from  Godaddy and then i renamed it to the following as per best practises.</p>
  <ol>
  <li><code>example.com.crt</code></li>
  <li><code>intermediate.crt</code></li>
  <li><code>example.com.pem</code></li>
  </ol>
  <p>And then I've concatenated the certificate with signing certificate in right order as discussed in this <a href="https://stackoverflow.com/a/52261299">answer</a>.</p>
  <pre><code>$ cat example.com.crt intermediate.crt &gt; bundle_chained.crt
  </code></pre>
  <hr />
  <h3>Exception:</h3>
  <p>Getting following exception while restarting Nginx.</p>
  <p><code>$ sudo nginx -t</code></p>
  <pre><code>nginx: [emerg] SSL_CTX_use_PrivateKey_file(&quot;/path/example_new.key&quot;) failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch)
  nginx: configuration file /etc/nginx/nginx.conf test failed
  
  </code></pre>
  <hr />
  <p>Here's what I tested:</p>
  <ul>
  <li><p>The certificate and private key has no trailing spaces.</p>
  </li>
  <li><p>I checked the <code>nginx.conf</code> and the directives are pointing to the
  correct private key and certificate.</p>
  </li>
  <li><p>I've checked md5 hashed of the key and bundle_chained</p>
  </li>
  </ul>
  <pre><code>$ openssl x509 -noout -modulus -in bundle_chained.crt | openssl md5
  (stdin)= d91144b76e2fa292e9aee71f10ac8b63
  
  $ openssl rsa -noout -modulus -in example.key | openssl md5
  (stdin)= a4773e7fa31e0bdc7edad15ee5412d3e
  </code></pre>
  <blockquote>
  <p>Note: Md5 hash are not matching</p>
  </blockquote>
  <ul>
  <li>Checked bundle_chained.crt using following and figure out that it doesn't look like my as I've specified Maharashtra <strong>ST</strong> and it is showing Arizona which is my CA.</li>
  </ul>
  <pre><code>$ openssl x509 -noout -text -in bundle_chained.crt
  
  
  Certificate:
      Data:
          Version: 3 (0x2)
          Serial Number:
              8d:a1:9d:55:8c:d8:as:45
          Signature Algorithm: sha256WithRSAEncryption
          Issuer: C = US, ST = Arizona, L = Scottsdale, O = &quot;GoDaddy.com, Inc.&quot;, OU = http://certs.godaddy.com/repository/, CN = Go Daddy Secure Certificate Authority - G2
          Validity
              Not Before: Aug 20 11:54:25 2020 GMT
              Not After : Aug 19 10:00:10 2022 GMT
          Subject: OU = Domain Control Validated, CN = example.com
          Subject Public Key Info:
              Public Key Algorithm: rsaEncryption
                  RSA Public-Key: (2048 bit)
  ....
  .....
  </code></pre>
  <blockquote>
  <p>Note: Please note that it did showing <strong>CN</strong> correct as <code>example.com</code> in my case.</p>
  </blockquote>
  <hr />
  <p>Thank you for your help. :)</p>