Running and Verifying Varnish
The following describes how to run and verify the Varnish when the local host is used as a backend object.
- Modify the backend IP address and port number for the reverse proxy test.(If the cache policy needs to be configured, obtain the latest Varnish Book from the official website.) In this example, the local host is configured as the backend object. The default port number is 80.
- Open the configuration file.
1vi /usr/local/varnish/config/default.vcl - Modify the file as follows, and save the change and exit:
vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = "127.0.0.1"; .port = "80"; } sub vcl_recv { } sub vcl_backend_response { } sub vcl_deliver { }
- Open the configuration file.
- Start the HTTP service of the backend object.
1systemctl start httpd
- Start Varnish.
1/usr/local/varnish/sbin/varnishd -a :12345 -T 127.0.0.1:6082 -s malloc,10GB -f /usr/local/varnish/config/default.vcl

Table 1 describes the related parameters.
Table 1 Varnish startup parameters Parameter
Description
-a address:port
Specifies the IP address and port number used by Varnish to monitor the HTTP service. The default IP address is the IP address of the local host.
-T address:port
Specifies the Telnet management address and port number of Varnish.
-s
Specifies the Varnish cache mode, which can be memory storage (malloc), disk file storage, or file storage. In this example, the malloc mode is used, and a total of 10 GB memory space is allocated.
-f
Specifies the location of the Varnish configuration file.
- Verify Varnish.
- Method 1: Enter http://IP:PORT in the address box of a browser to access the local host.
If the test page of the backend service is displayed, the Varnish verification is successful.
- Method 2: If the environment cannot be accessed using a browser, run the curl command to access the local host.
curl -k http://IP:PORT
Or
curl -k -s http://IP:PORT | head

Replace IP and PORT in the preceding commands with the actual values.
To stop Varnish, run the following command (do not run this command during service running):
pkill varnish
- To stop Varnish, run the following command (do not run this command during service running):
pkill varnish
- To uninstall Varnish and query the result:
- Uninstall Varnish that is installed from the source code.
1rm -rf /usr/local/varnish/
- Uninstall Varnish that is installed by using an RPM package.
1rpm -qa |grep varnish
1rpm -e --nodeps varnish-6.2.0
- Uninstall Varnish that is installed from the source code.
- Method 1: Enter http://IP:PORT in the address box of a browser to access the local host.