Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Configure W3 Total Cache With Varnish on WordPress

A practical, security-first guide to running Varnish as WordPress's reverse proxy while W3 Total Cache manages page caching and purge invalidation.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put Varnish in front of WordPress on the public HTTP/HTTPS ports, move Apache or Nginx to an origin port such as 8080, and let W3 Total Cache (W3TC) coordinate page caching and purge requests. Varnish serves anonymous pages quickly; W3TC tells it when posts, themes, plugins, or settings change. The configuration is safe only when purge access is restricted and logged-in, personalized, commerce, form, and preview responses are excluded from shared caching.

What the finished setup looks like

A working deployment has three distinct responsibilities:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Varnish: the reverse proxy that accepts public requests, stores eligible responses, and serves cache hits without contacting WordPress.
  • Apache or Nginx: the origin web server, listening on a private or restricted port such as 8080 instead of competing with Varnish for port 80.
  • W3 Total Cache: the WordPress-side cache and invalidation controller. It can purge Varnish after content changes and can also manage database, object, browser, and WordPress page-cache layers.

WordPress Developer Resources describes Varnish as especially powerful when paired with a WordPress caching plugin such as W3TC. Varnish decides what can be stored and served; WordPress must trigger removal of outdated entries.

Before changing ports or cache rules

Confirm these prerequisites before editing a live site:

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
  • Shell or control-panel access to the Varnish configuration and the origin web-server configuration.
  • Administrator access to WordPress and W3TC.
  • A backup of the current Apache/Nginx virtual-host files and Varnish VCL.
  • A decision about whether Varnish runs on the same machine as WordPress or on a separate reverse-proxy host.
  • The actual origin hostname or IP and port. The examples below use 127.0.0.1:8080; substitute the address used by your infrastructure.
  • A plan for TLS termination. HTTPS may terminate at Varnish, a load balancer, or another proxy, but the original scheme must be forwarded correctly to WordPress.

Do not apply the sample ports blindly on managed hosting. Some providers reserve a backend port, run Varnish on another node, or expose only a provider-specific purge endpoint.

Move Apache or Nginx behind Varnish

Varnish normally owns public port 80 and, when configured for TLS termination, port 443. The origin must listen elsewhere. Varnish Software’s installation tutorial uses port 8080 as the example origin port.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache origin

  1. Open Apache’s main configuration and change Listen 80 to Listen 8080.
  2. Change every affected virtual host from <VirtualHost *:80> to <VirtualHost *:8080>. Update any matching closing declarations only if your configuration syntax requires it.
  3. Check that firewall rules allow Varnish to reach port 8080 while preventing unwanted public access to that port.
  4. Validate the configuration with your platform’s Apache config-test command, then restart Apache.

Nginx origin

  1. In each relevant server block, change listen 80; to listen 8080;.
  2. Keep the correct server_name, document root, PHP-FPM settings, and TLS directives for the origin role.
  3. Test the configuration with nginx -t, then reload or restart Nginx.

After the change, test the origin directly from the Varnish host, for example with curl -I http://127.0.0.1:8080/. A successful response proves that Varnish has a reachable backend; it does not yet prove that public traffic is using Varnish.

Define the Varnish backend and purge authorization

Edit the VCL file used by your service, commonly /etc/varnish/default.vcl. This minimal foundation points Varnish at an origin on the same host and allows purge requests only from local addresses:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
vcl 4.1;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

acl purge {
    "localhost";
    "127.0.0.1";
    "::1";
}

sub vcl_recv {
    if (req.method == "PURGE") {
        if (!(client.ip ~ purge)) {
            return (synth(405, "PURGE not allowed"));
        }
        return (purge);
    }

    if (req.url ~ "\?$") {
        set req.url = regsub(req.url, "\?$", "");
    }

    set req.url = querystring.sort(req.url);
    unset req.http.Proxy;

    if (req.http.X-Forwarded-Proto) {
        # Preserve the value supplied by an upstream TLS terminator.
    } else if (server.port == 443) {
        set req.http.X-Forwarded-Proto = "https";
    } else {
        set req.http.X-Forwarded-Proto = "http";
    }
}

The backend host and port must match your topology. If the origin is on another machine, replace 127.0.0.1 and permit only the required network path. The purge ACL is a security boundary: add only trusted W3TC, deployment, or administrator source addresses. Never expose an unrestricted PURGE method to the internet.

The query-string cleanup removes a trailing empty query marker and sorts parameters so equivalent URLs can share a cache object. Removing the Proxy header avoids request-header ambiguity. The forwarded-protocol logic lets WordPress distinguish HTTP from HTTPS; adapt it if another proxy already sets and validates that header.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a dynamic-request policy

The minimal example above does not know which URLs are private on your site. Add rules that bypass or pass requests carrying authentication, authorization, preview, or user-specific cookies. Typical exclusions include:

  • Requests with an Authorization header.
  • Logged-in WordPress cookies such as wordpress_logged_in_.
  • Comment-author cookies when they personalize the page.
  • Cart, checkout, account, payment, order, and other commerce endpoints.
  • Form-processing URLs, preview links, search results that contain user-specific data, and membership areas.

Cookie names and paths vary by plugin. Identify them from your own responses and document every exception in the VCL. Do not remove a Set-Cookie header or force a cache hit merely to increase hit rate; doing so can disclose one visitor’s data to another.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Install a purge mechanism WordPress can call

Varnish can store a response, but it does not know that an editor changed a post. WordPress therefore needs a purge mechanism that sends an HTTP PURGE request when content changes.

Using a purge plugin

Varnish Software’s tutorial uses the Proxy Cache Purge plugin. The plugin issues purge requests and the VCL’s PURGE branch authorizes and processes them. Install only a maintained plugin compatible with your WordPress and PHP versions, then verify that its request originates from an address present in the purge ACL.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using W3 Total Cache reverse-proxy integration

W3TC can expose Varnish purge controls directly. This avoids a separate purge plugin when your host and W3TC version support the integration. The important test is not which interface you choose, but whether a publish action reaches Varnish and receives an authorized response. A plugin that can issue PURGE requests is ineffective if the ACL rejects its source address.

Configure W3 Total Cache

Page Cache

  1. In WordPress, open Performance > General Settings.
  2. Enable Page Cache.
  3. Choose a storage method available on your host. Disk: Enhanced is a common choice when no memory backend is provided, but it is not a universal best setting.
  4. Save the settings, then clear existing W3TC caches before testing.

Varnish and W3TC page cache can overlap. Decide which layer is authoritative for public HTML and make purge behavior explicit. Keeping two independent page caches without a reliable invalidation path is a common cause of stale pages.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Reverse Proxy

  1. Open the W3TC reverse-proxy settings. Depending on the version, this appears under Performance > General Settings or the related Page Cache settings.
  2. Enable Varnish cache purging.
  3. Enter the Varnish server address. Use the address reachable from the WordPress application, not necessarily the public hostname.
  4. Enter the provider-required port. A managed SSL example may use port 8080 for the Varnish service, while a self-managed installation commonly exposes Varnish on port 80 or 443 and keeps the origin on 8080.
  5. Save, then perform a manual purge and inspect the result before publishing real content.

Managed-hosting instructions are examples, not defaults. For example, a host may document Page Cache with Disk: Enhanced, Database Cache with Memcached, Object Cache with APC/APCu, and Browser Cache enabled. Enable database or object caching only when that backend is actually installed and supported; otherwise you can add latency or errors instead of reducing them.

Database, object, and browser cache

These layers solve different problems:

W3TC layer What it stores When to enable it Main caution
Page Cache Generated HTML for eligible requests Most public, anonymous content sites Must exclude private and dynamic responses
Database Cache Database query results Only when a suitable persistent backend is available and measurements justify it Can increase database or object-cache overhead on some sites
Object Cache WordPress objects and transients When Memcached, Redis, APCu, or another supported backend is provisioned Do not select a backend that is absent or misconfigured
Browser Cache Static assets in visitors’ browsers When cache headers and asset versioning are correctly managed Long lifetimes can delay CSS or JavaScript updates

Compatibility mode

W3TC’s advanced Page Cache settings include a Compatibility mode that is disabled by default and documented as recommended for interoperability with WordPress. The same documentation reports that disk-enhanced page-cache performance in its load tests decreased by about 20% at scale when the mode was enabled. That is a vendor-reported test result, not a guaranteed change for your site. Enable it when compatibility problems outweigh the measured cost, then benchmark your own workload.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Exclude private and dynamic content

Shared page caching is appropriate for a public article viewed by many anonymous visitors. It is unsafe for responses that vary by user, session, permissions, or submitted data. In W3TC, mark form pages and other sensitive paths as Never cache, and mirror the policy in Varnish.

Pages that normally bypass public caching

  • WordPress login, logout, password-reset, and account-management screens.
  • Logged-in dashboards and membership pages.
  • Shopping carts, checkout, payment, order history, and customer-account pages.
  • Forms that display a submission result, nonce, confirmation token, or user-specific data.
  • Preview URLs, editor previews, and staging-only routes.
  • Any endpoint that sets a session or personalized cookie.

Keep public article pages cacheable only when their response is identical for anonymous visitors. If a page contains a small personalized widget, separate that widget into an uncached request rather than disabling safety for the entire document.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make HTTPS and canonical URLs agree

Choose one place to terminate TLS and make every layer aware of the original scheme. If TLS terminates before Varnish, pass a trusted X-Forwarded-Proto: https header to Varnish and then to WordPress. If Varnish terminates TLS, set the header itself for encrypted requests.

Check all of the following after enabling HTTPS:

  • WordPress Site Address and WordPress Address use the intended HTTPS URL.
  • HTTP requests redirect once to HTTPS rather than entering a loop.
  • Canonical links, cookie security flags, and mixed-content rules reflect HTTPS.
  • The cache key does not allow an HTTP response to be served for an HTTPS request or vice versa.
  • Your provider’s W3TC reverse-proxy entry uses the backend port it documents for SSL deployments.

If WordPress believes every request is HTTP, it may generate insecure redirects, incorrect canonical URLs, or cookies that cannot be used over HTTPS.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Purge after publishing and configuration changes

Use a two-part purge whenever public output changes:

  1. Trigger a W3TC purge after publishing, editing, deleting, or scheduling content. Purge the affected URL and related archives when your configuration supports targeted invalidation; use a full purge when you cannot prove that dependent pages were invalidated.
  2. Ensure Varnish receives and authorizes the purge. A successful WordPress button click is not proof that Varnish removed the object.

Also purge after changing themes, plugins, menus, widgets, rewrite rules, VCL, or cache-related headers. Keep purge requests restricted by the ACL and log failures so an editor can distinguish a stale-cache problem from an origin problem.

Verify the deployment safely

  1. Test the origin: request the origin port from the Varnish host and confirm the expected WordPress response.
  2. Test the public URL twice while logged out: inspect response headers on the first and second requests. Depending on your configuration, look for headers such as Age, X-Varnish, Via, or a site-specific cache-status header. Header names are not universal, so document the ones your stack emits.
  3. Publish a harmless change: edit a test post, trigger the W3TC purge, and request the URL again. The edited content should appear without manually deleting files on the origin.
  4. Test a logged-in session: verify that account details, admin-bar output, and personalized content are not served from an anonymous cache object.
  5. Test a form or commerce flow: submit a non-production form or use a staging checkout and confirm that tokens, cookies, and confirmation pages remain private.
  6. Test HTTPS and redirects: verify one canonical redirect path and inspect the forwarded scheme seen by WordPress if your logs expose it.

Record headers, status codes, and observed timings from your own environment. There is no universal Varnish speed benchmark supplied for this configuration; a cache hit on one site may be slower than a miss on another if the origin, network, or TLS path differs.

Troubleshoot common failures

Symptom Likely cause Fix
502 or backend connection error Varnish points to the wrong host or port, or Apache/Nginx is stopped Test the origin directly, correct .host/.port, check firewall rules, and restart the origin.
Every request is a MISS Varnish is bypassing cookies or methods, responses prohibit caching, or the origin sends Set-Cookie Inspect request and response headers, confirm the URL is public, and adjust exclusions only after proving the response is safe to share.
Old content remains after publishing W3TC did not reach Varnish, the purge ACL rejected the caller, or dependent archive URLs were not purged Check purge logs and status, add only the correct trusted source to the ACL, and purge related URLs or the full cache when necessary.
Logged-in users see cached anonymous output Authentication cookies are not bypassing the cache Return pass for logged-in and personalized cookies in VCL and enable the corresponding W3TC exclusions.
HTTPS redirect loop or mixed content The original scheme is lost between TLS termination and WordPress Set and trust X-Forwarded-Proto, verify WordPress URLs, and remove conflicting proxy rewrites.
PURGE returns 405 The client IP is not in the purge ACL or the request is reaching the wrong Varnish instance Confirm the source address, endpoint, and port; add only the required trusted address and reload Varnish.
Styles or scripts stay old Browser cache or a static-file cache still holds the previous asset Use versioned asset URLs, purge W3TC and Varnish, and verify browser-cache lifetimes.

Self-managed versus managed Varnish

Decision factor Self-managed Varnish Managed WordPress hosting with Varnish
Control Full control of VCL, listeners, ACLs, and port layout Provider controls some ports, VCL features, and service lifecycle
Invalidation You must connect W3TC or a purge plugin to your ACL Provider may supply an integration, but you must follow its address and port requirements
Dynamic-content safety You maintain cookie, URL, and method exclusions Defaults may exist, but verify them against your plugins and commerce flows
TLS and networking You choose the termination point and forwarding headers The provider dictates the supported SSL topology and backend port
Operations You handle upgrades, monitoring, backups, rollback, and incident response The host handles more infrastructure work but may limit troubleshooting access

Choose self-management when you need custom VCL and have operational capacity. Choose a managed service when reliable defaults and support matter more than low-level control, while still verifying purge behavior and private-page exclusions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maintenance and rollback checklist

  • Keep a versioned copy of the working VCL and web-server listener configuration.
  • Document the public Varnish ports, origin port, backend address, purge clients, and TLS termination point.
  • After Varnish, W3TC, WordPress, PHP, theme, or commerce-plugin upgrades, repeat anonymous, logged-in, form, and HTTPS tests.
  • Monitor backend errors, purge failures, cache-hit status, and origin response times rather than relying on a single speed score.
  • If a deployment causes loops, privacy concerns, or widespread errors, disable public page caching or route traffic directly to the origin using your rollback plan, then restore one change at a time.

W3TC’s repository reports more than one million active installs on its 2026 page, but that figure does not predict compatibility with a particular host or plugin set. Your own headers, logs, and privacy tests are the authority for this deployment.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.