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 Aug 13, 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 in computer memory. This software acts as a middleman that hands saved pages directly to visitors, so your Apache server does not have to work as hard during traffic spikes.

You can set up this speed boost on Ubuntu 24.04 to make your website load much 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`.

Install Apache

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

Execute the command below to install Apache on Ubuntu.

🐧Bash / Shell
sudo apt update
sudo apt install apache2

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

Install Apache on Ubuntu

Change Apache port

Adjusting Apache's network ports lets Varnish intercept incoming web traffic. Shift Apache away from its default ports by moving HTTP traffic to port 8080 and HTTPS traffic to port 4433. Proper port configuration ensures Varnish Cache on Ubuntu 24.04 handles web requests correctly.

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

🐧Bash / Shell
sudo nano /etc/apache2/ports.conf

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

💻Code
# 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.

🐧Bash / Shell
sudo nano /etc/apache2/sites-available/000-default.conf

Modify port 80 to 8080 inside the VirtualHost block.

💻Code
<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.

🐧Bash / Shell
sudo systemctl restart apache2

Apache now listens for connections on port 8080.

Build and configure Varnish

Building Varnish Cache on Ubuntu 24.04 requires compiling the software from source. Grab the necessary packages and dependencies to get started. Executing `apt-get update && apt-get install varnish` pulls in all required components for proper operation on Ubuntu 24.04.

Deploy the required dependencies first by executing the commands below.

🐧Bash / Shell
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.

Command Prompt
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.

🐧Bash / Shell
sudo ldconfig

Launch Varnish using the following commands once installation completes successfully.

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

Successful execution produces output resembling the message below.

💻Code
Child launched OK

Run these commands to test the Varnish deployment.

💻Code
curl -I http://localhost

Verify the results match the output lines below.

💻Code
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.

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.

📚 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 *