October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

Fixing Nginx Config Test Errors With SSL and Varnish

A practical runbook for diagnosing NGINX configuration-test failures after SSL or Varnish changes, including certificate paths, PEM chains, upstream TLS, VCL and rollback-safe reloads.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When nginx -t fails after an SSL or Varnish change, do not restart the service or edit files at random. Read the first specific error, correct the referenced path, certificate, key, include, or upstream-TLS setting, run the test again, and reload only after it succeeds. NGINX checks both configuration syntax and whether it can open files named by the configuration, so a syntactically correct file can still fail because a certificate is missing, unreadable, malformed, or attached to the wrong effective server block.

What nginx -t checks

The command performs two checks in sequence: it parses the NGINX configuration for valid syntax, then tries to open files referenced by that configuration. Those files include certificates, private keys, included configuration files, logs, and other paths used by enabled modules. The final line, often shown as configuration file ... test failed, is only the status. The useful diagnosis appears earlier.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the basic test first

sudo nginx -t

Copy the complete output, not just the final line. It normally identifies a file and line number. That location is the starting point even when the actual mistake is in an included file or a server block inherited through a broader configuration.

Inspect the effective configuration with -T

sudo nginx -T

nginx -T performs the test and prints the expanded configuration, including files pulled in by include directives. Use it when the file named in your editor is not the file NGINX is actually loading, when duplicate server blocks exist, or when a certificate directive appears to be present but is not present in the effective HTTPS listener.

Read the error path, line number, and operating context

For every failure, verify the exact path and line reported by NGINX. A relative path, a misspelled filename, an unexpected include directory, or a symlink pointing to a removed certificate can produce the same broad “configuration file test failed” message.

  • Check spelling and capitalization. Linux paths are case-sensitive. FullChain.pem and fullchain.pem are different names.
  • Check the include path. A wildcard include may load an old or temporary file that you did not open in your editor.
  • Check readability by the NGINX master process. The private key should be restricted, but the master process must be able to read it while starting or reloading.
  • Check confinement controls. Mandatory access controls or service sandboxing can deny access even when ordinary filesystem permissions look correct.
  • Check the active binary and prefix. Testing one NGINX installation and reloading another can make a successful test irrelevant to the running service.

After correcting one issue, run nginx -t again. NGINX stops at the first blocking error, so a second problem may not appear until the first is fixed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fixing HTTPS server-block errors

An HTTPS listener needs a certificate and its matching private key in the effective server configuration. A minimal arrangement is:

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate     /etc/nginx/tls/fullchain.pem;
    ssl_certificate_key /etc/nginx/tls/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:6081;
    }
}

“no ‘ssl_certificate’ is defined”

This means NGINX has an HTTPS listener but cannot find a certificate directive for the server configuration it is using. Confirm that the listener includes listen 443 ssl;, that ssl_certificate is inside the intended server block or an inherited context, and that the file is included in the active configuration. Use nginx -T to locate duplicate port-443 blocks and confirm which directives are effective.

“cannot load certificate”

Common causes are a wrong path, an unreadable file, invalid PEM data, or a certificate and private key that do not belong together. Keep the public certificate (and its chain) available to NGINX, while applying restrictive permissions to the private key. Do not make the key world-readable merely to get the test to pass; instead, correct ownership, group access, or the service’s confinement policy so the NGINX master process can read it.

Certificate-chain order

When a full chain is supplied, the server certificate must be followed by the issuing intermediate certificates in the order expected by clients. NGINX documentation warns that an incorrect chain order can prevent NGINX from starting. If a newly assembled chain causes a startup failure, rebuild the PEM file in the correct order rather than changing protocol settings to mask the problem.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“BIO_new_file() failed”

This error indicates that NGINX could not open a referenced file. Recheck the complete path, symlink target, parent-directory traversal permissions, and any security policy that confines the service. The file can exist and still be inaccessible if one parent directory denies traversal.

“PEM_read_bio_X509_AUX() failed”

This points to invalid certificate contents or PEM formatting. Open the file and verify that it contains the expected PEM boundaries, with no truncated copy, binary encoding, accidental quotation marks, or unrelated text. Replace the file with a freshly exported certificate chain if the boundaries or contents are damaged.

Use current TLS protocol settings

For new configurations, use modern TLS settings. Current NGINX documentation presents TLS 1.2 and TLS 1.3 as the modern baseline in recent releases. Do not copy SSLv3 or weak, obsolete cipher examples into a new server block. Protocol directives cannot repair a missing certificate, malformed PEM file, or inaccessible key; fix the file error first.

Be precise about scope: a protocol setting on one server block may not affect another block selected by the same address and port. Inspect the expanded configuration when behavior differs between hostnames.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When NGINX connects to an HTTPS upstream

There are two separate TLS relationships in a reverse-proxy deployment:

  1. The client-to-NGINX connection, controlled by the public-facing certificate and the listen 443 ssl; server block.
  2. The NGINX-to-upstream connection, controlled by proxy_pass, trust settings, and the upstream’s certificate.

A certificate can be valid for public clients while the second connection fails. If the origin or Varnish listener is HTTPS, use an https:// URL in proxy_pass and configure an appropriate trusted CA file and verification policy. Then inspect protocol compatibility, the server name sent for SNI, the upstream trust chain, and whether the upstream requires a client certificate.

location / {
    proxy_pass https://origin.example.internal;
    # Add the trusted CA and verification directives required
    # by the upstream's certificate policy.
}

Do not treat disabling verification as a universal fix. It may conceal a wrong hostname, an incomplete trust chain, or a compromised connection. If verification is intentionally relaxed for an internal hop, document that decision and understand that encryption without identity validation does not provide the same protection as fully verified TLS.

Choose where TLS terminates when Varnish is present

Varnish can accept HTTPS at the edge and can also use HTTPS to a backend. Decide the termination point before changing certificates; otherwise one component may be configured for TLS while the next hop still expects plain HTTP.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Architecture Client connection Next hop Operational implication
NGINX terminates TLS Client to NGINX over HTTPS NGINX to Varnish over HTTP or HTTPS Keep the public certificate in NGINX and configure the proxy protocol for the Varnish listener.
Varnish terminates TLS Client to Varnish over HTTPS Varnish to NGINX or the application over HTTP or HTTPS The certificate belongs to the Varnish edge; NGINX must not be treated as the public TLS endpoint unless traffic is deliberately sent there.
TLS on both hops Client to the edge over HTTPS Encrypted HTTPS connection between proxy layers Each hop has its own certificate and trust requirements; a valid public certificate does not automatically validate the private upstream.

Use one clear owner for the public certificate whenever possible. Separate certificates may still be appropriate for an encrypted internal hop, but label which certificate serves clients and which one authenticates the upstream.

Configure HTTPS from Varnish to a backend

In VCL, adding .ssl = 1; to a backend definition tells Varnish to communicate with that backend over HTTPS.

vcl 4.1;

backend default {
    .host = "origin.example.internal";
    .port = "443";
    .ssl = 1;
}

The backend certificate still has to satisfy the connection policy. Confirm that the hostname, trust chain, protocol versions, and any required client certificate match what the backend expects. A Varnish configuration can load successfully while requests later fail during the backend handshake, so test an actual request after the configuration reload.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reload Varnish safely after certificate changes

Varnish handles TLS configuration changes through its load and commit workflow. Load the new TLS configuration, commit it, and only then reload the active configuration. Varnish documentation states that a reload error rolls changes back and that a reload cannot proceed while TLS changes remain uncommitted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Stage the new certificate, key, and VCL or TLS configuration with the intended ownership and permissions.
  2. Load the new configuration through the Varnish management interface.
  3. Commit the TLS change before requesting the reload.
  4. Reload the active configuration and check the management output for errors.
  5. If loading or committing fails, leave the previous working configuration in place, correct the certificate or VCL, and repeat the sequence.

This rollback behavior is different from editing a file and immediately restarting a service. Preserve the known-good Varnish state until the replacement has loaded and committed successfully.

A safe NGINX–Varnish troubleshooting sequence

  1. Capture the failure. Run sudo nginx -t and save all lines of output.
  2. Expand includes when necessary. Run sudo nginx -T to see the complete configuration NGINX parses.
  3. Fix the first reported path or line. Check spelling, include selection, symlinks, permissions, and confinement rules.
  4. Validate the HTTPS server block. Confirm listen 443 ssl;, ssl_certificate, and ssl_certificate_key are present in the effective block.
  5. Validate certificate material. Confirm PEM formatting, certificate-chain order, key readability, and certificate/key pairing.
  6. Validate the upstream scheme. Use https:// in proxy_pass when the next hop is HTTPS, then review CA trust, verification, SNI, protocol compatibility, and client-certificate requirements.
  7. Validate Varnish’s role. Decide whether NGINX, Varnish, or both terminate TLS and ensure each listener expects the protocol actually sent by the previous hop.
  8. Test again before changing runtime state. Do not reload or restart NGINX until nginx -t reports a successful test.
  9. Reload gracefully. Reload NGINX after the successful test, then perform the Varnish load/commit/reload sequence if Varnish configuration changed.
  10. Verify the live path. Test the public HTTPS listener and a request that reaches the configured upstream. A successful syntax test does not prove that the runtime handshake or backend response works.

Error reference: symptom to first action

Message or symptom Most useful first checks
no "ssl_certificate" is defined Inspect the effective port-443 server block with nginx -T; add or correctly inherit the certificate directive.
cannot load certificate Verify the path, readability, PEM validity, chain file, and certificate/key pairing.
BIO_new_file() failed Check the file path, symlink target, parent-directory permissions, and service confinement.
PEM_read_bio_X509_AUX() failed Inspect PEM boundaries and contents; replace truncated or incorrectly encoded certificate data.
configuration file ... test failed Ignore this as the diagnosis and fix the earlier, more specific error line.
upstream SSL handshake failed Check the upstream URL scheme, TLS compatibility, SNI name, trusted CA chain, hostname validation, and client-certificate requirement.
Varnish TLS reload failure Check certificate loading and commit state. A failed reload can preserve the prior configuration; correct the staged change before trying again.

Preventing the next outage

  • Keep certificate, chain, and key paths explicit and consistent across environments.
  • Separate public-edge certificates from private upstream certificates in both filenames and documentation.
  • Run nginx -t as a deployment gate before every NGINX reload.
  • Use nginx -T during reviews when includes or generated files are involved.
  • Test both the client-facing handshake and each encrypted upstream hop after certificate rotation.
  • Use graceful reloads rather than direct restarts when the service supports them, and retain the previous Varnish configuration until the replacement is committed.

The reliable pattern is deliberate separation: first make NGINX’s complete configuration parse and open every referenced file, then validate each TLS hop, then reload components in an order that preserves a working configuration if a staged change fails.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.