How to configure Nginx SSL/TLS passthrough with TCP load balancing

Here’s how you can configure Nginx to perform SSL/TLS passthrough with TCP load balancing:

  1. Install Nginx:
sudo apt-get update
sudo apt-get install nginx
  1. Create a new Nginx configuration file in the sites-available directory:
sudo nano /etc/nginx/sites-available/<your_site>
  1. Replace <your_site> with the desired name for your site.
  2. Add the following content to the file to configure Nginx for TCP load balancing:
stream {
upstream backend {
server backend1.example.com:443;
server backend2.example.com:443;
}

server {
listen 443;
proxy_pass backend;
proxy_ssl_certificate /path/to/certificate.crt;
proxy_ssl_certificate_key /path/to/certificate.key;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_session_reuse on;
proxy_ssl_preread on;
proxy_pass_request_headers on;
}
}

  1. Replace backend1.example.com and backend2.example.com with the IP addresses or hostnames of your backend servers.
  2. Replace /path/to/certificate.crt and /path/to/certificate.key with the paths to your SSL certificate and key, respectively.
  3. Create a symbolic link to the configuration file in the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/<your_site> /etc/nginx/sites-enabled/
  1. Test the Nginx configuration:
sudo nginx -t
  1. If the configuration is valid, restart Nginx to apply the changes:
sudo systemctl restart nginx
  1. Nginx is now configured to perform SSL/TLS passthrough with TCP load balancing. You can verify that it is working correctly by accessing your site using HTTPS.

Leave a Comment