Would you like to learn how to install Varnish and Nginx on Ubuntu Linux?In this tutorial, we are going to show you all the steps required to perform the Varnish installation on Ubuntu Linux in 5 minutes or less.

• Ubuntu 18.04
• Ubuntu 19.10
• Varnish 6.1.1
• Nginx 1.16.1

In our example, the Varnish service will listen on the TCP port 80.

In our example, the Nginx service will listen on the TCP port 8080.

Varnish – Related Tutorial:

On this page, we offer quick access to a list of tutorials related to Varnish.

Tutorial – Varnish Installation on Ubuntu Linux

Install the Varnish service.

Copy to Clipboard

Verify the default.vcl configuration file.

Copy to Clipboard

Here is the default.vcl configuration file content.

Copy to Clipboard

The Varnish service default configuration expects a web server to be running on the localhost on port 8080.

Edit the configuration file named Varnish located inside the directory named default.

Copy to Clipboard

Here is the Varnish configuration file, before our configuration.

Copy to Clipboard

Here is the Varnish configuration file, after our configuration.

Copy to Clipboard

In our example, we configured the Varnish service to run on port 80.

The Varnish service was configured to connect to a web server running on port 8080 of the localhost.

The Varnish service was configured to allocate 256mb of memory for cache.

Next, edit the Varnish service configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

In our example, we configured the Varnish service to run on port 80.

Reload the Varnish service configuration.

Copy to Clipboard

Restart the Varnish service.

Copy to Clipboard

Verify if the Varnish service is listening on the TCP port 80.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

You have finished the Varnish service configuration on Ubuntu LInux.

Tutorial Varnish – Nginx Installation on Ubuntu Linux

Install the Nginx service.

Copy to Clipboard

Edit the Nginx configuration file named default.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Change the Nginx default port from 80 to 8080.

Here is the file, after our configuration.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

Verify if the Nginx service is listening on the TCP port 8080.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

You have finished the Nginx configuration to use the Varnish service.

Tutorial Varnish – Testing your installation

After finishing installation, you need to test your Varnish configuration.

Open a browser software and enter the external IP address of your Varnish server.

In our example, the following URL was entered in the Browser:

• http://200.200.200.200

The Varnish service will communicate with the Nginx service and answer your request.

nginx welcome

Use the following command to verify if the Varnish service is answering your request.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

As you can see on the header, the Varnish service is answering the user request.