Skip to content
Follow
Ubuntu Linux

How to Install Varnish Cache on Ubuntu 24.04 with Apache

Richard
Written by
Richard
Mar 11, 2025 Updated Sep 15, 2026 3 min read
How to Install Varnish Cache on Ubuntu 24.04 with Apache
How to Install Varnish Cache on Ubuntu 24.04 with Apache

Varnish Cache speeds up your Ubuntu 24.04 server running Apache by storing copies of your web pages directly in computer memory. This software acts as a reverse proxy (a server that sits in front of web servers to handle client requests) that serves saved pages straight to visitors so your Apache server does not struggle during traffic spikes.

Advertisement

Set up this speed boost on Ubuntu 24.04 to make your website load faster for everyone.

⚡ Quick Answer

Install Apache and change its default port to 8080. Then, build and compile Varnish Cache from source code using `make install`. Finally, start Varnish using `varnishd -n /usr/local/sbin/ -a :80 -T localhost:6082 -b localhost:8080`.

Advertisement

Install Apache

Running Varnish with an Apache backend server requires a pre-existing Apache installation.

Execute the command below to install Apache on Ubuntu.

sudo apt update
sudo apt install apache2

Consult the post below for additional details regarding the Apache setup process.

Install Apache on Ubuntu

Advertisement

Change Apache port

To run Varnish Cache alongside Apache on Ubuntu 24.04, you need to change Apache port settings so Varnish can handle incoming web traffic on port 80. Moving Apache HTTP traffic to port 8080 and HTTPS traffic to port 4433 frees up the main web port for Varnish to intercept requests before passing them along to your web server.

Run the command below to open Apache's ports configuration file.

sudo nano /etc/apache2/ports.conf

Update the port numbers by changing 80 to 8080 and 443 to 4433.

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8080

<IfModule ssl_module>
Listen 4433
</IfModule>

<IfModule mod_gnutls.c>
Listen 4433
</IfModule>

Repeat this process for the default virtual host file.

Advertisement
sudo nano /etc/apache2/sites-available/000-default.conf

Modify port 80 to 8080 inside the VirtualHost block.

<VirtualHost *:8080>
# The ServerName directive sets the request scheme, hostname and port t>
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

Save changes and close the file.

Restart Apache by running the command below.

sudo systemctl restart apache2

Apache now listens for connections on port 8080.

Advertisement

Build and configure Varnish

When you build and configure Varnish Cache on Ubuntu 24.04, you install the core web accelerator software and all necessary compiler tools so it can speed up your Apache website. Getting the required packages and dependencies ready on your system ensures Varnish compiles properly and handles incoming traffic requests without errors.

Deploy the required dependencies first by executing the commands below.

sudo apt install make automake autotools-dev libedit-dev libjemalloc-dev libncurses-dev libpcre3-dev libtool pkg-config python3-docutils python3-sphinx graphviz autoconf-archive libpcre2-dev curl git

Download the Varnish packages with the following commands.

Navigate to the Varnish cache directory. Then, run `configure` and `make` sequentially to build the Varnish software. Compiling the source code prepares Varnish to cache incoming web traffic.

Advertisement
cd varnish-cache
sudo sh autogen.sh
sudo sh configure
sudo make

Execute the commands below to finalize the Varnish cache installation.

The Varnish Cache installation on Ubuntu 24.04 requires a few moments to finish. The compilation places the Varnish software inside the [/usr/local] directory, primed for configuration.

The main Varnish binary resides at /usr/local/sbin/varnishd. Execute the following command to refresh system library links and caches for recent shared libraries.

sudo ldconfig

Launch Varnish using the following commands once installation completes successfully.

Advertisement
sudo varnishd -n /usr/local/sbin/ -a :80 -T localhost:6082 -b localhost:8080

Successful execution produces output resembling the message below.

Child launched OK

Run these commands to test the Varnish deployment.

curl -I http://localhost

Verify the results match the output lines below.

HTTP/1.1 200 OK
Date: Tue, 11 Mar 2025 15:50:54 GMT
Server: Apache/2.4.58 (Ubuntu)
Last-Modified: Tue, 11 Mar 2025 15:20:51 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 2
Age: 0
Via: 1.1 Ubuntu (Varnish/trunk)
ETag: W/"29af-63012a259b614-gzip"
Accept-Ranges: bytes
Connection: keep-alive

Configuration is complete.

Advertisement

Conclusion:

Pairing Varnish Cache with an Apache backend on Ubuntu 24.04 boosts website performance and scalability. Caching web content at the proxy level minimizes backend server load and lowers user response times. Review these key points for implementation success:

  • Enhanced Performance: Varnish serves cached content quickly, leading to faster load times.
  • Reduced Server Load: Offloading requests from the backend Apache server minimizes resource consumption.
  • Easy Installation: Installing Varnish alongside Apache is straightforward, requiring just a few commands.
  • Customizable Configuration: Adjusting the Apache port and setting up Varnish allows for flexible server configurations.
  • Testing and Verification: Simple commands can verify successful installation and caching functionality.

Deploying Varnish Cache provides a reliable method for accelerating web applications on Ubuntu.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *