{"id":4393,"date":"2019-05-01T21:41:43","date_gmt":"2019-05-01T16:11:43","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4393"},"modified":"2026-10-22T14:18:41","modified_gmt":"2026-10-22T08:48:41","slug":"configure-varnish-with-apache-on-centos-7","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/configure-varnish-with-apache-on-centos-7\/","title":{"rendered":"How to Configure Varnish Cache With Apache on CentOS 7"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> May 05, 2019<br><strong>Last Updated:<\/strong> October 19, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Website performance is a critical factor in delivering a smooth user experience. Slow page loading, repeated requests to the web server, and inefficient handling of static content can increase server resource consumption and affect application responsiveness.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><a href=\"https:\/\/www.varnish.org\/docs\/\" target=\"_blank\" rel=\"noopener\">Varnish Cache<\/a><\/strong> is a high-performance HTTP reverse proxy that sits in front of a web server and caches eligible responses. By serving cached content directly, Varnish can reduce the number of requests reaching the backend server and improve response times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache HTTP Server is widely used to host websites and web applications. Combining Apache with Varnish allows administrators to separate request handling from content processing. Varnish receives incoming HTTP requests, checks whether a suitable cached response exists, and forwards requests to Apache when the content needs to be retrieved from the backend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain how to install and configure Varnish Cache with Apache on CentOS 7. You will learn how to configure the listening ports, define the Apache backend, start the services, verify HTTP responses, and troubleshoot common configuration issues.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This setup is useful for administrators managing websites, content management systems, and applications that can benefit from HTTP response caching.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> CentOS 7 reached end of life on June 30, 2024. This guide preserves the original CentOS 7 configuration approach for legacy environments. For new production deployments, use a currently supported Linux distribution and a compatible Varnish version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Varnish Cache?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish Cache is an HTTP accelerator designed to improve the performance of web applications by caching HTTP responses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It operates as a reverse proxy between clients and the backend web server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a client requests a page, Varnish checks whether it has a valid cached response. If the response is available, Varnish can return it without contacting Apache. Otherwise, Varnish forwards the request to Apache, receives the response, and may cache it according to the configured caching rules and HTTP headers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Benefits of Varnish Cache<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Faster response times:<\/strong> Serves eligible cached responses without repeatedly processing the same request in Apache.<\/li>\n\n\n\n<li><strong>Reduced backend workload:<\/strong> Decreases the number of requests that Apache must handle.<\/li>\n\n\n\n<li><strong>Improved scalability:<\/strong> Helps websites serve more requests when responses can be cached effectively.<\/li>\n\n\n\n<li><strong>Flexible caching rules:<\/strong> Allows administrators to control which requests and responses should be cached.<\/li>\n\n\n\n<li><strong>HTTP reverse proxy functionality:<\/strong> Routes requests between clients and backend servers.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Actual performance improvements depend on the application, cache hit ratio, server resources, network conditions, and caching configuration. No fixed performance multiplier is guaranteed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Architecture: Varnish Cache and Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this configuration, Varnish acts as the frontend HTTP reverse proxy, while Apache operates as the backend web server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish listens on port <code>80<\/code>, and Apache listens on port <code>8080<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Request Flow<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>A client sends an HTTP request to the server on port <code>80<\/code>.<\/li>\n\n\n\n<li>Varnish receives the request.<\/li>\n\n\n\n<li>Varnish checks its cache for a suitable response.<\/li>\n\n\n\n<li>If a valid cached response exists, Varnish returns it to the client.<\/li>\n\n\n\n<li>If the response is not cached, Varnish forwards the request to Apache on port <code>8080<\/code>.<\/li>\n\n\n\n<li>Apache processes the request and returns the response to Varnish.<\/li>\n\n\n\n<li>Varnish caches the response when permitted by its caching rules and the response headers.<\/li>\n\n\n\n<li>Varnish returns the response to the client.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Flow Map 1: Overall Architecture<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow-1024x683.png\" alt=\"Varnish Cache and Apache architecture diagram showing how HTTP requests flow from a web client to Varnish on port 80 and then to Apache on port 8080 on a cache miss. Varnish stores cacheable responses and returns cached or backend responses to the client.\" class=\"wp-image-12371\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow-1024x683.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow-300x200.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow-768x512.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow-272x182.png 272w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-and-Apache-Caching-Flow.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before installing Varnish Cache, ensure that the following requirements are met.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A CentOS 7 server with administrative access.<\/li>\n\n\n\n<li>Apache HTTP Server installed and working.<\/li>\n\n\n\n<li>Root access or a user with <code>sudo<\/code> privileges.<\/li>\n\n\n\n<li>Network access to the required package repositories.<\/li>\n\n\n\n<li>Ports <code>80<\/code> and <code>8080<\/code> available for the intended services.<\/li>\n\n\n\n<li>A website or application that Apache can serve.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Verify the Operating System<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/centos-release<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check Apache Status<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If Apache is not installed, install it using the following command, provided the required repositories remain available:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo yum install -y httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable and start Apache:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl enable httpd\nsudo systemctl start httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the Apache version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">httpd -v<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> CentOS 7 is no longer supported. Its standard repositories may no longer provide packages normally. Legacy systems may require archived repositories, which should be handled carefully because they do not provide ongoing security updates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install the Required Repository<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original CentOS 7 installation procedure uses the Extra Packages for Enterprise Linux (EPEL) repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the EPEL release package:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo yum install -y epel-release<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Update the package metadata:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo yum makecache<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that the repository is available:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">yum repolist<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Repository availability and package versions depend on the system&#8217;s repository configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Varnish Cache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install Varnish using the package manager:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo yum install -y varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, verify the available Varnish version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo varnishd -V<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output identifies the installed Varnish version and build information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Version compatibility:<\/strong> Varnish configuration syntax, service parameters, and package availability can vary by version. Review the documentation corresponding to the version installed on the server before applying configuration changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Start and Enable Varnish<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start the Varnish service:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl start varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the service at boot:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl enable varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the service status:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the service does not start, inspect its logs:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo journalctl -u varnish -n 100 --no-pager<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">At this stage, Varnish should be installed. The next step is to configure it to receive public HTTP requests and communicate with Apache.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Configure Varnish to Listen on Port 80<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By default, the original CentOS 7 Varnish package commonly uses port <code>6081<\/code> for HTTP traffic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this configuration, Varnish must listen on port <code>80<\/code>, while Apache will use port <code>8080<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Varnish service parameter file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/varnish\/varnish.params<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Locate the listening port parameter:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">VARNISH_LISTEN_PORT=6081<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change it to:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">VARNISH_LISTEN_PORT=80<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the file contains a separate listening address parameter, make sure it is configured appropriately for your environment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Important Configuration Note<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The exact service parameter file and startup options depend on the installed Varnish package. Some versions use a systemd service override or another configuration file rather than <code>\/etc\/varnish\/varnish.params<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the service definition if the expected parameter is missing:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl cat varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use the configuration mechanism supported by the installed package rather than assuming every Varnish version uses the same startup parameters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Configure the Apache Backend in Varnish<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish needs to know where to retrieve content when a request cannot be served from its cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Varnish VCL configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/varnish\/default.vcl<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Configure the backend as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vcl 4.0;\n\nbackend default {\n    .host = \"127.0.0.1\";\n    .port = \"8080\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This example uses VCL 4.0 syntax, which is appropriate for compatible legacy Varnish releases. Check the VCL version and syntax requirements of the installed release before using it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Backend Configuration Explanation<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>backend default<\/code>: Defines the backend server Varnish uses to retrieve content.<\/li>\n\n\n\n<li><code>.host = \"127.0.0.1\"<\/code>: Specifies that Apache is running on the same server.<\/li>\n\n\n\n<li><code>.port = \"8080\"<\/code>: Specifies the port on which Apache will listen.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If Apache runs on a separate server, change the backend address and port to match that server&#8217;s configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Validate the Varnish Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before restarting Varnish, check the VCL syntax:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo varnishd -C -f \/etc\/varnish\/default.vcl<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The exact command and required options can vary by Varnish version. If the installed package requires additional parameters or uses a different VCL configuration path, use its documented validation procedure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Correct any reported configuration errors before proceeding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Configure Apache to Listen on Port 8080<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache commonly listens on port <code>80<\/code> by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because Varnish will now handle incoming HTTP traffic on port <code>80<\/code>, Apache must use port <code>8080<\/code> for the backend connection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Apache configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/httpd\/conf\/httpd.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Find the existing directive:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 80<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change it to:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 8080<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Review Virtual Host Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If your Apache configuration includes virtual hosts that explicitly listen on port <code>80<\/code>, update them to use port <code>8080<\/code> where appropriate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;VirtualHost *:8080>\n    ServerName example.com\n    DocumentRoot \/var\/www\/html\n\n    &lt;Directory \"\/var\/www\/html\">\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n&lt;\/VirtualHost><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>example.com<\/code> with your actual hostname.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Review any additional Apache configuration files under:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/etc\/httpd\/conf.d\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check for conflicting port directives:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo grep -RniE '^[[:space:]]*Listen[[:space:]]|&lt;VirtualHost' \\\n    \/etc\/httpd\/conf \/etc\/httpd\/conf.d<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid changing unrelated SSL virtual hosts unless you have planned and configured their corresponding ports and proxy paths.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test Apache Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apachectl configtest<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Syntax OK<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If Apache reports an error, correct it before restarting the service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Restart Apache and Varnish<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After updating both configurations, restart Apache first:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check Apache:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then restart Varnish:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check Varnish:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If either service fails, inspect its logs before proceeding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache logs:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo journalctl -u httpd -n 100 --no-pager<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish logs:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo journalctl -u varnish -n 100 --no-pager<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Flow Map 2: Installation and Configuration Workflow<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart.png\"><img decoding=\"async\" width=\"683\" height=\"1024\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart-683x1024.png\" alt=\"\" class=\"wp-image-12372\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart-683x1024.png 683w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart-200x300.png 200w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart-768x1152.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/CentOS-7-Varnish-Setup-Flowchart.png 1024w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Verify Listening Ports<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check whether Varnish and Apache are listening on their expected ports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ss -lntp | grep -E ':(80|8080|6081)\\b'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The expected configuration is:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Service<\/th><th class=\"has-text-align-right\" data-align=\"right\">Expected Port<\/th><th>Purpose<\/th><\/tr><tr><td>Varnish<\/td><td class=\"has-text-align-right\" data-align=\"right\">80<\/td><td>Receives incoming HTTP requests<\/td><\/tr><tr><td>Apache<\/td><td class=\"has-text-align-right\" data-align=\"right\">8080<\/td><td>Processes backend requests<\/td><\/tr><tr><td>Varnish default alternative port<\/td><td class=\"has-text-align-right\" data-align=\"right\">6081<\/td><td>Should not be the active public HTTP listener in this setup<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The output should show Varnish listening on port <code>80<\/code> and Apache listening on port <code>8080<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The precise process names and output formatting may differ by package version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If another service already occupies port <code>80<\/code>, Varnish may fail to start. Identify the conflicting process before making changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 9: Test the Apache Backend Directly<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before testing Varnish, verify that Apache responds on port <code>8080<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/127.0.0.1:8080\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If Apache is configured correctly, it should return an HTTP response.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a successful request, you may see:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">HTTP\/1.1 200 OK<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The exact headers depend on your Apache configuration and website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the request fails, investigate Apache&#8217;s listening port, virtual host configuration, document root, application status, and logs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 10: Test the Varnish Frontend<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once Apache is working on port <code>8080<\/code>, test the Varnish frontend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/127.0.0.1\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a website configured to return a successful response, you should see an HTTP status such as:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">HTTP\/1.1 200 OK<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A response may include headers similar to these:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">HTTP\/1.1 200 OK\nDate: ...\nServer: Apache\nX-Varnish: ...\nAge: 0\nVia: 1.1 varnish\nContent-Type: text\/html; charset=UTF-8<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is an illustrative example, not a guaranteed output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The presence, order, and values of response headers depend on the Varnish version, VCL configuration, backend response, and header handling.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What Do the Headers Mean?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>HTTP status:<\/strong> Indicates whether the request succeeded or encountered an error.<\/li>\n\n\n\n<li><strong>X-Varnish:<\/strong> May contain identifiers associated with Varnish request processing.<\/li>\n\n\n\n<li><strong>Age:<\/strong> When present, indicates the approximate age in seconds of a cached response.<\/li>\n\n\n\n<li><strong>Via:<\/strong> May identify an HTTP intermediary.<\/li>\n\n\n\n<li><strong>Server:<\/strong> May identify the backend server or another component, depending on header configuration.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>X-Varnish<\/code> and <code>Via<\/code> headers alone do not prove that a response was served from the cache. Likewise, an <code>Age<\/code> value of <code>0<\/code> does not establish that caching is broken.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 11: Verify Cache Behavior<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A successful HTTP response confirms that the request completed, but it does not necessarily mean that Varnish is caching the content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To inspect Varnish activity, use the tools available in your installed version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo varnishstat<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Look at counters associated with client requests, cache hits, and cache misses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common counter names in compatible Varnish releases include:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">MAIN.cache_hit\nMAIN.cache_miss\nMAIN.client_req<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Counter names and availability vary between releases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make several requests to a cacheable page:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/127.0.0.1\/\ncurl -I http:\/\/127.0.0.1\/\ncurl -I http:\/\/127.0.0.1\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Observe the cache-related counters before and after the requests.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Flow Map 3: HTTP Request and Cache Decision<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss.png\"><img decoding=\"async\" width=\"683\" height=\"1024\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss-683x1024.png\" alt=\"Varnish Cache with Apache configuration showing the HTTP request flow between Varnish and Apache\n\" class=\"wp-image-12373\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss-683x1024.png 683w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss-200x300.png 200w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss-768x1152.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/HTTP-Caching-Flowchart_-Hit-or-Miss.png 1024w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> A cache miss does not automatically mean the response will be stored. Varnish may bypass caching or decline to cache a response because of its VCL rules, cookies, authorization headers, cache-control directives, or other conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 12: Configure Firewall Access<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the server uses firewalld, allow HTTP traffic on port <code>80<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the firewall status:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo firewall-cmd --state<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If firewalld is active, add the HTTP service:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo firewall-cmd --permanent --add-service=http\nsudo firewall-cmd --reload<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the rule:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo firewall-cmd --list-services<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this design, port <code>8080<\/code> should normally remain inaccessible to public clients because it is the backend port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If Apache and Varnish run on the same server, keep Apache&#8217;s backend listener restricted to the intended interfaces where possible. A loopback-only listener can be used if the deployment supports it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a remote backend, permit access to port <code>8080<\/code> only from the Varnish server or other explicitly authorized systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Common Issues<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Varnish Fails to Start<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check the service status:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status varnish<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Review recent logs:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo journalctl -u varnish -n 100 --no-pager<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible causes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Invalid VCL syntax.<\/li>\n\n\n\n<li>Incorrect service startup parameters.<\/li>\n\n\n\n<li>Another service already listening on port <code>80<\/code>.<\/li>\n\n\n\n<li>Unsupported configuration directives.<\/li>\n\n\n\n<li>Permission or runtime directory problems.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Validate the configuration and inspect the service definition before restarting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Apache Fails to Start<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apachectl configtest\nsudo systemctl status httpd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the logs:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo journalctl -u httpd -n 100 --no-pager<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible causes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Incorrect virtual host ports.<\/li>\n\n\n\n<li>Duplicate <code>Listen<\/code> directives.<\/li>\n\n\n\n<li>Syntax errors in Apache configuration files.<\/li>\n\n\n\n<li>Port conflicts.<\/li>\n\n\n\n<li>Incorrect file permissions.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure Apache uses the intended backend port and that all virtual hosts are consistent with the new configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Varnish Returns HTTP 503<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>503 Service Unavailable<\/code> response can occur when Varnish cannot successfully communicate with its backend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache directly:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/127.0.0.1:8080\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the backend definition:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo cat \/etc\/varnish\/default.vcl<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that Apache is running and listening on the configured backend address and port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also check Varnish logs for connection errors and backend health problems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Website Loads, but Cache Hits Do Not Increase<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A working website does not necessarily mean that its responses are cacheable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check Varnish statistics:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo varnishstat<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Review the VCL configuration and response headers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Potential causes include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The response contains <code>Cache-Control: no-cache<\/code> or <code>Cache-Control: private<\/code>.<\/li>\n\n\n\n<li>The response sets cookies that affect caching behavior.<\/li>\n\n\n\n<li>The request contains an authorization header.<\/li>\n\n\n\n<li>The VCL explicitly passes the request to Apache.<\/li>\n\n\n\n<li>The response is not cacheable under the configured rules.<\/li>\n\n\n\n<li>The application generates unique or dynamic responses.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Do not force caching for authenticated or personalized content without understanding the security implications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Apache Is Still Listening on Port 80<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo grep -RniE '^[[:space:]]*Listen[[:space:]]|&lt;VirtualHost' \\\n    \/etc\/httpd\/conf \/etc\/httpd\/conf.d<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the active listeners:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ss -lntp | grep -E ':(80|8080)\\b'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Update any conflicting Apache configuration files and restart Apache after validating the configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. SELinux Prevents Apache from Using Port 8080<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On SELinux-enabled CentOS 7 systems, custom HTTP ports may require additional policy configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the SELinux mode:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">getenforce<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the permitted HTTP ports:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo semanage port -l | grep http_port_t<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If port <code>8080<\/code> is not permitted for the relevant HTTP service, configure the appropriate SELinux policy using the supported administrative tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, where the port is not already assigned to another type:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo semanage port -a -t http_port_t -p tcp 8080<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the port is already defined under another type, review the existing assignment before making a modification.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>semanage<\/code> command may require the appropriate policy management package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not disable SELinux as a shortcut for resolving configuration problems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Security and Production Recommendations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before deploying this architecture in production, consider the following practices:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Use a supported operating system:<\/strong> CentOS 7 no longer receives normal security maintenance. Plan a migration to a supported distribution.<\/li>\n\n\n\n<li><strong>Keep the backend private:<\/strong> Restrict access to Apache&#8217;s backend port so clients cannot bypass Varnish unintentionally.<\/li>\n\n\n\n<li><strong>Protect personalized content:<\/strong> Carefully evaluate caching rules for login pages, dashboards, shopping carts, and user-specific responses.<\/li>\n\n\n\n<li><strong>Use HTTPS appropriately:<\/strong> Configure TLS termination at Varnish or an upstream proxy\/load balancer according to your architecture. Plain HTTP on port <code>80<\/code> does not provide encryption.<\/li>\n\n\n\n<li><strong>Monitor cache performance:<\/strong> Track hit ratio, request rate, backend errors, memory usage, and response times.<\/li>\n\n\n\n<li><strong>Validate configuration changes:<\/strong> Test VCL and Apache configuration before applying changes to production.<\/li>\n\n\n\n<li><strong>Maintain a rollback plan:<\/strong> Back up configuration files and document how to restore the previous ports and service configuration.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Back Up the Configuration Files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before modifying the configuration, create backups:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo cp -a \/etc\/varnish\/default.vcl \\\n    \/etc\/varnish\/default.vcl.backup\n\nsudo cp -a \/etc\/httpd\/conf\/httpd.conf \\\n    \/etc\/httpd\/conf\/httpd.conf.backup<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the Varnish parameter file exists:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo cp -a \/etc\/varnish\/varnish.params \\\n    \/etc\/varnish\/varnish.params.backup<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keep backups in a location protected from unauthorized access and include them in your configuration management process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Configuring Varnish Cache in front of Apache is an effective way to introduce HTTP response caching into a web hosting environment. With Varnish listening on port <code>80<\/code> and Apache serving requests on port <code>8080<\/code>, incoming HTTP traffic can pass through the cache before reaching the backend web server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we covered installing Varnish, configuring the backend, changing Apache&#8217;s listening port, validating the configuration, testing HTTP responses, inspecting cache activity, and troubleshooting common service and connectivity issues.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most important point is that <strong>a successful HTTP response does not automatically mean that caching is working<\/strong>. Administrators should also verify cache statistics, response headers, backend health, and the application&#8217;s caching behavior.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For production deployments, use appropriate cache rules, protect personalized content, monitor performance, and maintain a clear rollback procedure. Because CentOS 7 is no longer supported, migrating to a supported operating system should also be a priority for legacy environments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When configured and monitored correctly, Varnish Cache and Apache can work together to reduce backend load and improve web application responsiveness.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions (FAQ)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is Varnish Cache?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish Cache is an HTTP reverse proxy that can cache eligible responses and serve them to clients without repeatedly contacting the backend web server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Why use Varnish with Apache?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish can reduce Apache&#8217;s workload by serving cached responses directly. This can improve response times and help applications handle higher request volumes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Which port does Varnish use in this configuration?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish listens on port <code>80<\/code>, which receives incoming HTTP requests from clients.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/modify-virtualhost-single-domain-cpanelapache-2-4\/\">How to Modify the Apache VirtualHost Configuration for a Single Domain in cPanel<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/add-custom-virtualhost-configurationapache-2-4\/\">How to Configure a Custom VirtualHost in cPanel with Apache 2.4<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need Help with Apache Virtual Hosts in Ubuntu?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Need help with Apache Virtual Hosts in Ubuntu, domain configuration, website hosting, or Apache server management? Our experts can help with Apache configuration, Linux server administration, web server optimization, security hardening, and cloud hosting solutions. Get in touch with our team <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: May 05, 2019Last Updated: October 19, 2026 Introduction Website performance is a critical factor in delivering a smooth [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[635,633,634],"class_list":["post-4393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-aws","tag-apache-web-server","tag-centos7","tag-varnish-cache-server","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-18R","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Varnish-Cache-with-Apache-on-CentOS-7.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4393"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4393\/revisions"}],"predecessor-version":[{"id":12439,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4393\/revisions\/12439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/12375"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}