Current Location: Home> Latest Articles> How to Configure Nginx Proxy Server to Support SSL Certificate Verification for Web Services

How to Configure Nginx Proxy Server to Support SSL Certificate Verification for Web Services

gitbox 2025-06-24

1. What is SSL Certificate Verification?

SSL certificate verification is a security measure that confirms the identity of a server using the SSL encryption protocol. It ensures that data transmitted over the network is not tampered with or intercepted, protecting the confidentiality and integrity of communication.

By verifying the server’s public key, SSL certificate verification effectively prevents man-in-the-middle attacks and guarantees reliable and non-repudiable data transmission.

2. Steps to Configure Nginx Proxy Server to Support SSL Certificate Verification

2.1 Generating an SSL Certificate

First, install the OpenSSL tool, then run the following command to generate a self-signed certificate:

<span class="fun">openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -days 365</span>

This command generates a self-signed certificate valid for 365 days, producing the files server.crt (certificate) and server.key (private key).

2.2 Configuring SSL in Nginx

Edit the Nginx configuration file (usually located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf), and add the following to enable HTTPS and redirect HTTP requests:

server {  
    listen 80;  
    server_name example.com;  
    return 301 https://$server_name$request_uri;  
}  
<p>server {<br>
listen 443 ssl;<br>
server_name example.com;</p>
ssl_certificate_key /path/to/server.key;  

location / {  
    proxy_pass http://backend;  
    proxy_redirect off;  
    proxy_set_header Host $host;  
    proxy_set_header X-Real-IP $remote_addr;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
}  

}

Here, requests to port 80 are redirected to port 443. Replace the certificate and key paths with your actual file locations.

2.3 Enabling Client SSL Certificate Verification

To enhance security, Nginx can be configured to verify client SSL certificates. Modify the configuration as follows:

server {  
    listen 443 ssl;  
    server_name www.example.com;  
ssl_client_certificate /path/to/ssl.crt;  

ssl_certificate /path/to/new.crt;  
ssl_certificate_key /path/to/new.key;  

location / {  
    proxy_pass http://localhost:8080;  
}  

}

The directive ssl_verify_client on; enables client certificate verification, while ssl_client_certificate specifies the trusted certificate authorities, ensuring only requests with valid client certificates are accepted.

3. Summary

SSL certificate verification is fundamental for securing web services. Properly configuring SSL on the Nginx proxy server effectively protects the confidentiality and integrity of data transmissions. This article explained the complete process of generating SSL certificates, configuring Nginx for HTTPS, and enabling client certificate verification to help users strengthen their server security.