PEM Bundle Merger

Merge multiple PEM certificates into a bundle

PEM Inputs

Input 1

Paste PEM blocks to merge into a bundle

The PEM Bundle Merger combines multiple individual PEM certificates into a properly ordered certificate chain file, automatically determining the correct sequence from end-entity to root -- critical for configuring TLS on web servers like nginx, Apache, and HAProxy. Paste your certificates in any order and get a correctly assembled chain ready for deployment.

Understanding Certificate Chain Assembly

Every TLS connection requires the server to present a certificate chain that lets the client build a trust path from the server's leaf certificate to a root CA it trusts. If the chain is incomplete or in the wrong order, clients will reject the connection with errors like "unable to verify the first certificate" or "certificate chain too long." Building this chain correctly is one of the most common tasks in TLS server administration, and it is surprisingly easy to get wrong.

The challenge is that Certificate Authorities often deliver certificates in pieces. You might receive your leaf certificate in one email, the intermediate in another, and the root from a separate download page. Or your automation tool generates a CSR and receives back just the leaf, leaving you to find the correct intermediate yourself. The result is a collection of individual PEM files that need to be assembled in the right order before your web server will accept them.

This merger automates that assembly. Paste all your certificates in any order, and the tool analyzes each one's Subject and Issuer fields to figure out which is the leaf, which are intermediates, and which is the root. It then outputs them in the correct sequence: leaf first, followed by intermediates, with the root optionally last. The output is a single PEM file that you can drop directly into your nginx or Apache configuration.

How to Merge PEM Certificates into a Chain

  1. Paste your individual PEM certificates (in any order)
  2. The tool analyzes subject and issuer fields to determine the correct chain order
  3. Review the automatically ordered chain and any validation warnings
  4. Copy or download the merged PEM bundle

Example: Building a Certificate Chain

Input -- three certificates pasted in wrong order:

Certificate 1: CN=R3, O=Let's Encrypt  (intermediate)
Certificate 2: CN=ISRG Root X1         (root)
Certificate 3: CN=www.example.com      (leaf)

Output -- correctly ordered chain:

PositionSubjectIssuerRole
1CN=www.example.comCN=R3, O=Let's EncryptLeaf (end-entity)
2CN=R3, O=Let's EncryptCN=ISRG Root X1Intermediate
3CN=ISRG Root X1CN=ISRG Root X1Root (optional)

The merged output is a single PEM file with certificates concatenated in the correct order, ready for server deployment.

When to Use This Tool

  • Assembling CA-provided certificates -- many Certificate Authorities deliver the leaf and intermediates as separate files that you must concatenate in the right order
  • Fixing broken chains -- rebuild a certificate chain that is causing "unable to verify the first certificate" or "incomplete chain" errors
  • Preparing for server deployment -- create a properly formatted chain file for nginx ssl_certificate, Apache SSLCertificateChainFile, or HAProxy PEM bundles
  • Cross-platform chain building -- combine certificates from different sources (downloaded root, issued intermediate, generated leaf) into a unified chain
  • Certificate renewal -- merge a new leaf certificate with existing intermediate certificates after renewal
  • Multi-intermediate chains -- assemble chains with two or more intermediates (common with some commercial CAs) in the correct order

How Certificate Chain Order Works

TLS requires certificates to be presented in a specific order during the handshake. The server sends its chain to the client, and the client must be able to build a trust path from the leaf to a root CA it trusts.

Chain Validation Logic

The merger verifies the chain by matching each certificate's Issuer field to the next certificate's Subject field:

Leaf:         Subject=CN=www.example.com
              Issuer=CN=R3, O=Let's Encrypt
                 | (Issuer matches next Subject)
Intermediate: Subject=CN=R3, O=Let's Encrypt
              Issuer=CN=ISRG Root X1
                 | (Issuer matches next Subject)
Root:         Subject=CN=ISRG Root X1
              Issuer=CN=ISRG Root X1  (self-signed)

Common Chain Errors Detected

The merger warns about problems it finds during assembly:

  • Missing intermediate -- a gap exists where no certificate's Subject matches the previous certificate's Issuer
  • Duplicate certificates -- the same certificate appears more than once in the input
  • Cycle detected -- certificates form a loop instead of a linear chain
  • Multiple leaf certificates -- more than one certificate is not the Issuer of any other certificate in the input
  • Unnecessary root -- the self-signed root CA is included; most server configurations should omit it

Server Configuration for Merged Chains

After merging, use the chain file in your server configuration:

nginx:

ssl_certificate     /etc/ssl/certs/example.com-chain.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;

Apache:

SSLCertificateFile    /etc/ssl/certs/example.com.crt
SSLCertificateChainFile /etc/ssl/certs/example.com-chain.pem

HAProxy expects the private key appended to the chain in a single file.

Chain Assembly in Practice

The most common mistake when building chains is confusing which intermediate certificate to use. Large CAs like DigiCert and Sectigo maintain multiple intermediates, and using the wrong one produces a chain that looks complete but fails validation because the Subject/Issuer linkage is broken at one step. When you receive your certificate from the CA, always download the intermediates from the same order or the same page -- do not reuse intermediates from a previous certificate order, because the CA may have rotated its intermediates since then.

Another frequent pitfall is including the root CA in the chain for public-facing servers. While technically harmless, it wastes bandwidth and serves no purpose because clients already have root certificates in their trust stores. The exception is internal deployments with a private CA, where the root is not pre-installed in client trust stores and must be included in the chain or installed on clients separately. If you are unsure whether to include the root, leave it out for public servers and include it for internal services.

After assembling your chain, always test it before deploying to production. The fastest check is openssl verify -untrusted chain.pem leaf.pem, which walks the chain and reports any validation errors. You can also test the complete deployment with openssl s_client -connect yourserver.com:443 and check that the output shows a valid chain with depth 0, 1, and 2 entries. If openssl s_client shows "Verify return code: 0 (ok)," your chain is correct.

Frequently Asked Questions

Should I include the root CA certificate in the merged chain? For public-facing servers, no. Root certificates are pre-installed in client trust stores (browsers, operating systems). Including the root adds unnecessary bytes to every TLS handshake. Omit it unless you are deploying to an environment where clients may not have the root pre-installed, such as embedded systems or private CA deployments.

What order should the certificates be in? The correct order is: leaf certificate first, followed by intermediates in order from closest to the leaf to closest to the root, with the root optionally last. This tool handles ordering automatically. If your CA provides a "CA bundle" file separately, it contains the intermediates in the correct order -- simply prepend your leaf certificate.

Why am I getting "unable to get local issuer certificate" after deploying my chain? This error typically means a required intermediate certificate is missing from your chain. Use the PEM Bundle Splitter to examine what certificates are actually in your file, then add any missing intermediates. Also verify that the chain is in the correct order -- some servers are sensitive to ordering.

Can I merge certificates from different CAs? Not into a single valid chain. A certificate chain must follow a single trust path where each certificate's Issuer matches the next certificate's Subject. Certificates from different CAs have different trust paths and cannot be combined into one chain. If you need to serve multiple certificates (e.g., RSA and ECDSA), configure your server to use separate chains for each.

How do I verify my merged chain is correct? Use OpenSSL to validate: openssl verify -untrusted chain.pem leaf.pem. A successful result shows "leaf.pem: OK". You can also check a deployed chain with openssl s_client -connect yourserver.com:443 and look for "Verify return code: 0 (ok)" in the output.

What if my CA provides a single "full chain" file? Some CAs provide a single file that already includes the leaf and intermediates in the correct order. In this case, you can use it directly without merging. If you are unsure of the contents, paste it into the PEM Bundle Splitter first to inspect each certificate, then re-merge if needed.

Related Tools

IPparse•Free Network & Subnet Calculator Tools

© 2026 IPparse. All tools run locally in your browser.

100% Privacy-First • No Data Collected