Nginx with SSL Termination | All About (2024)

This ultimate guide covers all the important aspects of setup Nginx with SSL termination on the load balancer, find out how to set up to make yours even better. At Bobcares, we will help our customers with any sort of queries as a part of our Server Management Services.

Introduction to Nginx load balancer with SSL Termination

Nginx is a popular reverse proxy and load balancer that focuses on level 7 application traffic and determines pooled backend server which is the best available to serve the request. Relieving on the upstream web and application servers for the computational load SSL/TLS encryption.

This will reduce your SSL management overhead since the OpenSSL updates the keys and certificates which accordingly can be managed from the load balancer itself.

About SSL Termination

The SSL termination is the process that occurs on the load balancer which handles the SSL encryption/decryption so that traffic between the load balancer and backend servers in HTTP. To be specific the Nginx can be configured as a load balancer to distribute incoming traffic around several backend servers.

Indeed the backends must be also secured by restricting access to the load balancer’s IP.

Nginx with SSL Termination | All About (1)

Configuration setup for Nginx Load Balancing

Let’s take a look at the steps involved in the process of Nginx load balancing with SSL termination.
This article makes use of the following 3 Parts:

Section1 (Frontend)

  • Hostname: loadbalancer
  • Private IP: 10.130.227.31

Section2 (Backend)

  • Hostname: web1
  • Private IP: 10.130.227.12

Section3 (Backend)

  • Hostname: web2
  • Private IP: 10.130.227.23

Domain name – website.com

Note that private networking must be enabled to all these sections.Even more, you can use the below command to upgrade your OS.

apt-get update && apt-get upgrade -y 

Reboot each server to apply the upgrades. Eventually, this is important since OpenSSL helps to keep secure and have the better version. Also, have Nginx virtual host setup for the domain with the upstream module load balancing backends server.

Prior to setting up the Nginx load balancing, you should have Nginx installed on your VPS. You can simply install it quickly with the command “apt-get

apt-get install nginx

On the other two backend servers, update and install Apache:

apt-get install apache2

Later finish up with installing PHP on both backend servers:

apt-get install php5 libapache2-mod-php5 php5-mcrypt

Generate SSL Certificate

We will now go through the SSL certificate generation process:
First, create an SSL certificate directory.

mkdir -p /etc/nginx/ssl/website.comcd /etc/nginx/ssl/website.com

In addition, Create a private key:

openssl genrsa -des3 -out private key.key 2048

now remove its passphrase:

openssl rsa -in privatekey.key -out privatekey.key

The next step is to create a CSR (Certificate Signing Request) you can request this from any SSL service provider or can also generate a self-signed certificate with the following command.

openssl req -new -key privatekey.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey privatekey.key -out SSLcertificate.crt

Once this is done new directory will be created with the following files:

  • privatekey.key
  • CAcertificate.pem
  • SSLcertificate.crt

Furthermore, we need to create a virtual hosts file inside the Nginx directory

nano /etc/nginx/sites-available/website.com

Now add the upstream module containing the private IP addresses of the backend servers and save this file.

upstream mywebapp1 { server 10.130.227.12; server 10.130.227.23; }
server { listen 80; server_name website.com www.website.com; location / { proxy_pass http://mywebapp1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}

Moreover, perform a configuration test to check for errors and then reload the Nginx server and as result, the load balancing will be configured.

service nginx configtest
service nginx reload

Enable SSL

Additionally, we can now take a quick look at enabling SSL byadding the following directives to the virtual hosts file ” /etc/nginx/sites-available/website.com”.

 listen 443 ssl;ssl on;ssl_certificate /etc/nginx/ssl/website.com/SSLcertificate.crt;ssl_certificate_key /etc/nginx/ssl/website.com/privatekey.key;ssl_trusted_certificate /etc/nginx/ssl/website.com/CAcertificate.pem; 

You will be getting server block like this:

server { listen 80; listen 443 ssl; server_name website.com www.website.com; ssl on; ssl_certificate /etc/nginx/ssl/website.com/SSLcertificate.crt; ssl_certificate_key /etc/nginx/ssl/website.com/privatekey.key; ssl_trusted_certificate /etc/nginx/ssl/website.com/CAcertificate.pem; location / { proxy_pass http://mywebapp1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}

Finally, Check for configuration errors and reload the Nginx service.

service nginx configtest
service Nginx reload

Securing The Backend Servers

Currently, the website hosted on the backend servers can be directly accessed by anyone who knows the public IP, we can prevent it by configuring the web servers on the backends to listen to the private interface.

You can follow the given steps to do this in Apache:

First, search for “Listen 80” in the ports.conf file and replace with your backend private IP:

nano /etc/apache2/ports.conf
Listen 10.130.227.23:80

Further, you have to restart Apache.

service apache2 restart

The next step is to have HTTP restricted for the load balancer’s private IP. The following firewall rule achieves this.

iptables -I INPUT \! --src LB_IP_ADDRESS-p tcp --dport 80 -j DROP

Hardening SSL Configuration

This section explains how to configure SSL.

Enabling SSL session cache improves the performance the HTTPS websites. This must be placed with “ssl_trusted_certificate” in the directive.

ssl_session_cache shared:SSL:20m;ssl_session_timeout 10m;

For the SSL connection, you need to specify the protocols and ciphers.

ssl_prefer_server_ciphers on;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

Enable it with the add_headerdirective.

add_header Strict-Transport-Security "max-age=31536000";

Check for any configuration errors and later reload the Nginx service.

service nginx configtest && service nginx reload

Final Configuration Check

After hardening the SSL termination, the configuration file will be resulted as below:

/etc/nginx/sites-available/website.com
upstream mywebapp1 { server 10.130.227.12; server 10.130.227.23;}server { listen 80; listen 443 ssl; server_name website.com www.website.com; ssl on; ssl_certificate /etc/nginx/ssl/website.com/SSLcertificate.crt; ssl_certificate_key /etc/nginx/ssl/website.com/privatekey.key; ssl_trusted_certificate /etc/nginx/ssl/website.com/CAcertificate.pem; ssl_session_cache shared:SSL:20m; ssl_session_timeout 10m; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS; add_header Strict-Transport-Security "max-age=31536000"; location / { proxy_pass http://mywebapp1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}

In the final analysis, do an SSL server test and this progress should get an A+ grade. Meanwhile, run the curl test again to check if everything is working correctly.

curl https://website.com/test.php https://website.com/test.php https://website.com/test.php

[Need assistance with a different issue? We are available 24/7.]

Conclusion

To conclude, The Nginx load balancer with SSL termination is the process that works to reduce SSL management overhead and terminate HTTPS traffic from clients which can also be managed from the load balancer itself.

On the whole, our Support team provides instructions on how to quickly fix the problem.

PREVENT YOUR SERVER FROM CRASHING!

Never again
lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server
24/7 so that it remains lightning fast and secure.

GET STARTED

Related posts:

  1. How to enable SSL in Virtualmin
  2. Secure osTicket with Let’s Encrypt SSL Certificates – How we do it
  3. WHM: Install SSL certificate for Hostname
  4. Bitnami SSL certificate installation | How-to Guide
Nginx with SSL Termination | All About (2024)

FAQs

What is nginx SSL termination? ›

The SSL termination is the process that occurs on the load balancer which handles the SSL encryption/decryption so that traffic between the load balancer and backend servers in HTTP. To be specific the Nginx can be configured as a load balancer to distribute incoming traffic around several backend servers.

How to secure nginx with SSL? ›

Now, let's secure NGINX with Let's Encrypt:
  1. Step 1: Install Certbot (Let's Encrypt Client) ...
  2. Step 2: Obtain Let's Encrypt SSL Certificate. ...
  3. Step 3: Automatically Renew the Certificate. ...
  4. Step 4: Verify Certificate Renewal (Optional) ...
  5. Step 5: Test Your HTTPS Setup. ...
  6. Step 6: Adjust Your NGINX Configuration (Optional)

How to configure SSL termination? ›

Add the SSL Termination Rule

From the control panel, click Networking in the main menu, then click Load Balancers. Click on the load balancer you want to modify, then click the Settings tab to go to its settings page. In the Forwarding Rules section, click Edit.

How to disable SSL in nginx? ›

Nginx: Disabling the SSL v3 Protocol
  1. Locate your SSL Protocol Configuration on your Nginx server. For example, ...
  2. Add or update the following lines in your configuration: ssl_protocols TLSv1. ...
  3. Restart Nginx. For example, type the following command: ...
  4. You have successfully disabled the SSL v3 protocol.

Why is SSL termination needed? ›

SSL termination or SSL offloading decrypts and verifies data on the load balancer instead of the application server. Spared of having to organize incoming connections, the server can prioritize on other tasks like loading web pages. This helps increase server speed.

How to run nginx without SSL? ›

To configure NGinx without a public certificate you would use HTTP (ie abandon encryption). HTTPS is designed around public/private encryption so it would not make sense for Nginx to not use this. It is possible for you to create a self signed certificate, and for users to "pin" that.

Where is the nginx SSL certificate stored? ›

By default, the nginx. conf configuration file is stored in the /usr/local/nginx/conf directory. If you moved the nginx. conf configuration file to a different location, you can run the nginx -t command to obtain the new path to the configuration file and replace /usr/local/nginx/conf/nginx.

What SSL protocols does nginx recommend? ›

Using TLS 1.2 and TLS 1.3 on an nginx server is important because these versions of the TLS protocol provide stronger security features and improved performance compared to older versions.

How do I protect my nginx server? ›

  1. Disable Unused Nginx Modules. ...
  2. Disable the Display of Nginx Version Number. ...
  3. Set Client Buffer Size Limitations. ...
  4. Disable Unnecessary HTTP Methods. ...
  5. Disable TRACE and TRACK. ...
  6. Install the ModSecurity Module. ...
  7. Configure Nginx to Include an X-Frame-Options Header. ...
  8. Disable Older SSL Protocols in the Nginx Configuration.
Sep 9, 2024

What is the difference between SSL pass through and SSL termination? ›

SSL offloading (aka SSL termination): The Load Balancer decrypts incoming HTTPS traffic, and sends it to the backend server unencrypted. SSL passthrough: The Load Balancer does not decrypt incoming HTTPS traffic, and sends it to the backend server 'as is'.

What is the SSL termination handshake process? ›

Here's how SSL/TLS termination works:

This handshake includes the client and server exchanging encryption keys and agreeing on a shared encryption algorithm. In the case of SSL/TLS termination, a network endpoint (such as a load balancer) receives the incoming encrypted traffic.

What is the default TLS protocol for nginx? ›

ingress-nginx defaults to using TLS 1.2 and 1.3 only, with a secure set of TLS ciphers.

What is SSL termination in nginx? ›

SSL termination refers to the process of decrypting encrypted traffic before passing it along to a web server. What is SSL Termination? Approximately 90% of web pages are now encrypted with the SSL (Secure Sockets Layer) protocol and its modern, more secure replacement TLS (Transport Layer Security).

How to configure nginx with SSL? ›

How to Install and Configure Your SSL Certificate
  1. Primary and intermediate certificates. You should've received a your_domain_name. ...
  2. Copy the certificate files to your server. ...
  3. Concatenate the primary and intermediate certificates. ...
  4. Edit the Nginx virtual hosts file. ...
  5. Restart Nginx. ...
  6. Congratulations!

How to replace SSL certificate in nginx? ›

To do this, you must open your Nginx configuration file, which is generally located in /etc/nginx/sites-available/default or similar pathways, and alter the ssl_certificate and ssl_certificate_key directives to reflect the pathway where you saved your new files.

What are the different types of SSL termination? ›

Two main types of SSL offloading exist: SSL termination: Your SSL load balancer sits on the edge, and it grabs all incoming traffic. After decryption, the balancer passes on the traffic via non-encrypted means. SSL bridging: Your SSL load balancer sits on the edge and grabs all incoming traffic.

What is SSL offloading? ›

SSL offloading is the process of removing the SSL-based encryption from incoming traffic to relieve a web server of the processing burden of decrypting and/or encrypting traffic sent via SSL. The processing is offloaded to a separate device designed specifically for SSL acceleration or SSL termination.

What is SSL_ciphers nginx? ›

The ssl_protocols and ssl_ciphers directives can be used to require that clients use only the strong versions and ciphers of SSL/TLS when establishing connections. Since version 1.9.1, NGINX uses these defaults: ssl_protocols TLSv1 TLSv1.

Top Articles
Treasure on Mercury: NASA spacecraft finds 10-mile-thick diamond mantle - CNBC TV18
Korean Webtoon Publisher Kakao On The Industry’s Anti-Piracy Crusade
417-990-0201
Costco The Dalles Or
Wmlink/Sspr
Deshret's Spirit
Jesus Revolution Showtimes Near Chisholm Trail 8
Mikayla Campinos Videos: A Deep Dive Into The Rising Star
Fire Rescue 1 Login
Herbalism Guide Tbc
Wnem Radar
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Sport-News heute – Schweiz & International | aktuell im Ticker
The Grand Canyon main water line has broken dozens of times. Why is it getting a major fix only now?
Bridge.trihealth
Metro Pcs.near Me
Viha Email Login
Ford F-350 Models Trim Levels and Packages
Dulce
Pearson Correlation Coefficient
What Are The Symptoms Of A Bad Solenoid Pack E4od?
Surplus property Definition: 397 Samples | Law Insider
Colonial Executive Park - CRE Consultants
Airline Reception Meaning
Skycurve Replacement Mat
Renfield Showtimes Near Paragon Theaters - Coral Square
Sorrento Gourmet Pizza Goshen Photos
Bolsa Feels Bad For Sancho's Loss.
Hesburgh Library Catalog
Jayme's Upscale Resale Abilene Photos
Cardaras Funeral Homes
3 Ways to Drive Employee Engagement with Recognition Programs | UKG
Kiddie Jungle Parma
Red Sox Starting Pitcher Tonight
Dubois County Barter Page
Haunted Mansion Showtimes Near Cinemark Tinseltown Usa And Imax
Pokemmo Level Caps
Craigslist Albany Ny Garage Sales
The Land Book 9 Release Date 2023
AI-Powered Free Online Flashcards for Studying | Kahoot!
Banana Republic Rewards Login
Mcalister's Deli Warrington Reviews
Unveiling Gali_gool Leaks: Discoveries And Insights
Yakini Q Sj Photos
Grand Valley State University Library Hours
Atu Bookstore Ozark
Csgold Uva
Adams-Buggs Funeral Services Obituaries
Craigslist Com Brooklyn
Itsleaa
Texas 4A Baseball
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6209

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.