How to Setup Varnish SSL Termination with Nginx Web Server on Rocky Linux 8

 

 

Varnish is a powerful HTTP accelerator designed for content-heavy dynamic websites. When used with Nginx, it can help offload the SSL termination process. In this guide, we will walk through the steps to set up Varnish for SSL termination with an Nginx web server on Rocky Linux 8.

Step 1: Update Your System

Start by ensuring your system is up to date:

sudo dnf update -y

Step 2: Install Varnish and Nginx

Install Varnish and Nginx by running the following command:

sudo dnf install -y varnish nginx

Step 3: Configure Nginx

Edit the Nginx configuration file to set it up for Varnish. Open the default configuration file:

sudo nano /etc/nginx/nginx.conf

Add the following server block to configure Nginx to listen on port 8080:

server {
        listen 8080;
        server_name your_domain.com;  # Replace with your domain

        location / {
            proxy_pass http://127.0.0.1:8081;  # Varnish will listen on this port
            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;
        }
    }

Step 4: Configure Varnish

Edit the Varnish default configuration file:

sudo nano /etc/varnish/default.vcl

Set the backend to Nginx:

backend default {
        .host = "127.0.0.1";
        .port = "8081";
    }

Make sure Varnish listens on port 8080 for incoming SSL traffic:

sub vcl_recv {
        if (req.http.X-Forwarded-Proto) {
            set req.http.X-Forwarded-Proto = "https";
        }
    }

Step 5: Set Up SSL Certificates

Obtain SSL certificates using Certbot:

sudo dnf install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain.com

Follow the prompts to configure your SSL certificate. Certbot will automatically configure Nginx for SSL.

Step 6: Start and Enable Varnish and Nginx

Start Varnish and enable it to run at startup:

sudo systemctl start varnish
sudo systemctl enable varnish

Start Nginx and enable it to run at startup:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 7: Access Your Website

Now, you can access your website securely at:

https://your_domain.com

Conclusion

You have successfully set up Varnish for SSL termination with Nginx on Rocky Linux 8. This configuration will improve the performance and security of your web applications.

If you're looking for a reliable hosting solution for your Varnish and Nginx setup, consider using Windows VPS UK. With Windows VPS, you can efficiently host your applications and ensure high performance. Whether you need VPS UK Windows or Windows Virtual Private Servers, you'll find a solution that fits your requirements.

For larger deployments or enterprise needs, explore Windows Virtual Dedicated Server Hosting or Virtual Private Server Hosting Windows. Whether you're located in the UK, Italy, or elsewhere, Windows VPS Italy and UK VPS Windows offer reliable hosting options. Visit Windows VPS Hosting UK to discover the best hosting solutions for your web applications.

  • 0 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

Boost Your Ubuntu System's Performance with a Swap File: A Step-by-Step Guide

What is a Swap File? A swap file in Ubuntu serves as dedicated virtual memory on your hard...

How to Migrate ISPConfig 2, ISPConfig 3.x, Confixx, CPanel or Plesk to ISPConfig 3.2 (single server)

Introduction Migration from other control panels like ISPConfig 2, ISPConfig 3.x, Confixx,...

How to Install and Configure Zabbix Server and Client on Rocky Linux 9

Introduction Zabbix is an open-source monitoring solution that provides real-time...

How to Install CockroachDB Cluster on Debian 12

Introduction CockroachDB is a distributed SQL database built to handle large-scale,...

How to Install Joomla with Apache and Let's Encrypt SSL on AlmaLinux 9

Introduction Joomla is a popular open-source content management system (CMS) used to build...