NGINX Reverse Proxy: Fixing HTTPS Connection with Invalid Backend Certificate

Abstract: Resolve NGINX 502 errors caused by invalid backend SSL certificates by setting proxy_ssl_verify off.

Created: 2026-08-12 by
When an NGINX reverse proxy encounters a backend server with an invalid or self-signed SSL certificate, clients receive browser security warnings that block access. To resolve this while maintaining the reverse proxy architecture, you must configure NGINX to ignore upstream certificate validation errors by setting proxy_ssl_verify off;. This directive allows NGINX to establish a secure tunnel to the backend without validating its identity, ensuring seamless connectivity for end-users who are served valid certificates from the proxy itself.

Understanding the Connection Flow

In a standard reverse proxy setup, the client connects to NGINX over HTTPS using a valid certificate issued by a trusted Certificate Authority (CA). NGINX then initiates a separate connection to the backend application server. If the backend uses a self-signed certificate, a wildcard certificate not matching the hostname, or an expired certificate, the TLS handshake between NGINX and the backend fails strict verification checks. By default, NGINX acts as a strict validator and will reject the upstream connection if the certificate chain is incomplete or untrusted, resulting in HTTP 502 Bad Gateway errors or SSL handshake failures logged in the NGINX error log. The core issue arises because NGINX treats the backend connection independently of the client connection. Even if the client trusts NGINX's certificate, they do not inherently trust the backend's certificate. Therefore, the proxy must be explicitly instructed to relax its security requirements regarding the upstream server's identity. This is particularly common in internal networks, development environments, or when managing legacy applications that cannot easily obtain public CA-signed certificates.

Configuring Upstream SSL Verification

To fix the invalid backend certificate issue, you need to modify the server block within your NGINX configuration file. The specific directive required is proxy_ssl_verify. Setting this to off disables the verification of the peer certificate during the SSL handshake with the upstream server. Add the following line inside the location block or the server block where your reverse proxy rules are defined:
server {
    listen 443 ssl;
    server_name example.com;

    # Existing SSL configuration for the client-facing side
    ssl_certificate /etc/ssl/certs/example.crt;
    ssl_certificate_key /etc/ssl/private/example.key;

    location / {
        proxy_pass https://backend-server-ip;
        
        # Disable verification of the upstream backend certificate
        proxy_ssl_verify off;
        
        # Optional: Specify the backend hostname if it differs from the IP
        # proxy_ssl_server_name on;
    }
}
It is crucial to understand that proxy_ssl_verify off only affects the connection between NGINX and the backend. The connection between the user's browser and NGINX remains fully secured and verified. This means that while NGINX ignores the backend's certificate validity, the data transmitted between the client and NGINX is still encrypted and authenticated. If your backend server presents a certificate with a hostname that does not match the address used in proxy_pass, you may also need to enable proxy_ssl_server_name on;. This ensures that the SNI (Server Name Indication) extension is sent correctly, although it does not bypass the verification failure if the certificate is fundamentally invalid.

Security Implications and Best Practices

Disabling upstream SSL verification introduces a man-in-the-middle (MITM) risk between NGINX and the backend. An attacker on the same network segment as the backend could potentially intercept or modify traffic if they can spoof the backend's IP address. However, in most reverse proxy scenarios, the backend resides in a private network or a controlled environment where such risks are mitigated by network segmentation. For production environments where security is paramount, the recommended approach is to install a valid, CA-signed certificate on the backend server. Tools like Let's Encrypt can automate this process even for internal services if proper DNS records are configured. Alternatively, you can create a private PKI (Public Key Infrastructure) and distribute the root CA certificate to all NGINX instances, allowing them to verify the backend's self-signed certificate properly. If you are configuring similar setups for other applications, you might find our guide on How to disable SSL checking on Nginx? helpful for understanding broader contexts of SSL handling. Additionally, for specific use cases like Paperless-ngx, we discuss Configuring SSL Passthrough with Certificates on Nginx Reverse Proxy for Paperless-ngx, which offers an alternative architectural approach.

Diagnostics and Troubleshooting

After applying the configuration change, always test the syntax before reloading NGINX. Run the following command to ensure there are no syntax errors:
sudo nginx -t
If the test passes, reload the service:
sudo systemctl reload nginx
Monitor the error logs to confirm the issue is resolved:
sudo tail -f /var/log/nginx/error.log
You should no longer see errors related to "SSL_do_handshake() failed" or "certificate verify failed." Instead, you should see successful proxy connections. If issues persist, verify that the backend server is actually listening on port 443 and that firewall rules allow traffic between the NGINX host and the backend.

Frequently Asked Questions

Does disabling proxy_ssl_verify expose my users to attacks?

No, it does not directly expose users to attacks because the client-to-proxy connection remains fully encrypted and verified. The risk is limited to the potential interception of data between the proxy and the backend, which is usually mitigated by network isolation.

Can I use a custom CA certificate instead of disabling verification?

Yes, you can specify a custom CA bundle using proxy_ssl_trusted_certificate and set proxy_ssl_verify on;. This allows NGINX to verify the backend's self-signed certificate against your internal root CA, providing security without disabling checks entirely.

Why am I still getting SSL errors after adding proxy_ssl_verify off?

Ensure that you have reloaded NGINX after making changes. Also, check if the backend server is responding with a different certificate than expected, or if there are intermediate certificate issues that require proxy_ssl_server_name on; to resolve SNI mismatches.

Is this method suitable for public-facing backends?

It is generally not recommended for public-facing backends due to the loss of mutual authentication. For public services, always use valid, publicly trusted certificates to prevent man-in-the-middle attacks between the proxy and the origin server.

How do I verify the backend certificate details manually?

You can use OpenSSL to inspect the backend certificate directly from the NGINX server using the command: openssl s_client -connect backend-ip:443 -servername backend-hostname. This helps identify expiration dates, subject names, and issuer information to diagnose certificate validity issues.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More