October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Install and Configure Varnish With Apache

A practical guide to placing Varnish in front of Apache: move Apache to port 8080, configure the VCL backend, bind Varnish to port 80, verify both services, and troubleshoot 503 errors.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Varnish should listen on the public HTTP port while Apache continues to serve the site as the origin server on a different port. On a single Debian or Ubuntu host, the dependable layout is Varnish on :80, Apache on :8080, and a VCL backend pointing to 127.0.0.1:8080. You must change Apache’s main listener and every enabled virtual host, then reload systemd if you changed Varnish’s service unit.

This guide walks through that arrangement, shows how to verify each layer independently, and covers separate-origin hosts, TLS termination, multiple backends, hostname resolution, and the common causes of Varnish 503 errors.

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.

What the Apache–Varnish layout does

Varnish is the front-end HTTP cache. It accepts client requests, decides whether an object can be served from cache, and contacts Apache only when it needs a fresh response. Apache remains the origin server: it runs your application, reads files, executes server-side code, and generates responses that Varnish can store and reuse.

Varnish Cache documentation describes this relationship by saying that Varnish has a concept of a “backend” or “origin” server. In this setup, Apache is that backend. Varnish does not replace Apache; it sits in front of it.

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

A same-host deployment uses separate sockets so the two daemons do not compete for port 80:

Component Typical address Role
Varnish :80 Public HTTP listener and cache
Apache 127.0.0.1:8080 or :8080 Origin web server
VCL backend .host = "127.0.0.1", .port = "8080" Where Varnish connects for misses

Varnish’s official quick-start guidance identifies port 8080 as a good alternative HTTP port for the web server. The exact port is not mandatory, but it must be free, consistently configured in Apache, and identical in the VCL backend.

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

Plan the deployment before changing ports

Check the operating system and packages

The commands below target Debian and Ubuntu systems using systemd. You need root or sudo access, a working Apache installation, and a maintenance window long enough to restart both services. Ensure your firewall permits public HTTP on port 80 and, if you use a separate administrative path, does not expose Apache’s origin port unnecessarily.

Install Varnish after refreshing package metadata:

sudo apt-get update
sudo apt-get install varnish

On RHEL-compatible distributions, use the Varnish repository and package workflow documented by Varnish Cache for your release. The service names and paths normally follow the distribution’s conventions; Apache configuration is under /etc/httpd rather than /etc/apache2.

Inventory every Apache binding

Do not assume that changing the first site file is enough. Apache can load listeners and virtual hosts from the main configuration, enabled-site links, included snippets, and generated files. Before editing, search all active configuration for port 80:

sudo apachectl -S
sudo grep -R "Listen 80|VirtualHost .*:80" /etc/apache2

apachectl -S reports the virtual hosts Apache has parsed. The recursive search helps find an additional Listen 80 or a virtual host that would continue claiming the port after the primary edit.

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

Install and configure Varnish on Debian or Ubuntu

1. Confirm Apache works directly first

Before adding a cache, request the site from Apache itself. At this stage Apache may still be on port 80. Record the expected status code, headers, redirects, and application behavior. If the origin is already broken, inserting Varnish will make diagnosis harder.

After you eventually move Apache to 8080, the equivalent direct test is:

curl -i http://127.0.0.1:8080/

Use an appropriate Host header when name-based virtual hosting is in use:

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
curl -i -H 'Host: example.test' http://127.0.0.1:8080/

Replace example.test with a hostname configured on your server. A response here proves that Apache, its virtual-host selection, and the application can operate without Varnish.

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

2. Move Apache’s listener to port 8080

Edit /etc/apache2/ports.conf and change the active HTTP listener:

Listen 80

to:

Listen 8080

Then edit every enabled virtual host that currently binds to port 80. Change:

<VirtualHost *:80>

to:

<VirtualHost *:8080>

Check files under /etc/apache2/sites-enabled as well as included files elsewhere in the Apache configuration. A site left on *:80 can keep Apache bound to the public port, or can leave that virtual host unavailable once Varnish takes the port.

Validate the syntax before restarting:

sudo apachectl configtest

Only a successful syntax result should be followed by an Apache restart:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo systemctl restart apache2
sudo systemctl status apache2

Now test the origin directly on 8080. If it fails, fix Apache before proceeding. Typical causes include a missed virtual-host binding, an application that generates absolute URLs for the old port, or a module configuration that was included only in the original site file.

3. Define the Varnish backend in /etc/varnish/default.vcl

Replace the file contents, or adapt the existing distribution example, so the backend points to Apache’s actual address and port:

vcl 4.1;

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

The VCL version must be supported by the installed Varnish package. A backend must be specified with either a .host or a .path attribute, but not both, as stated in the Ubuntu Varnish backend reference. For a TCP connection to Apache, use .host and .port as shown.

You may use the server’s address or a hostname instead of 127.0.0.1. A numeric loopback address avoids DNS dependency on a same-host installation. If you choose a hostname, remember that Varnish resolves it when the VCL is compiled; changing DNS later does nothing until the VCL is reloaded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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)

4. Configure Varnish to listen on port 80

Package defaults differ by distribution and Varnish release. Inspect the active unit before editing so you preserve required arguments:

systemctl cat varnish

Configure the unit, or create a supported systemd drop-in override, so the start command includes a listener of -a :80 and loads /etc/varnish/default.vcl. A unit’s existing memory, security, storage, and PID arguments may be necessary; do not replace the complete command with a minimal example unless you have verified the package’s requirements.

A drop-in is generally safer than editing a vendor unit directly. The exact override syntax depends on the unit’s existing ExecStart; if you replace it, systemd requires clearing the previous command first:

sudo systemctl edit varnish

Within the editor, use the package’s documented command as the base and ensure its Varnish arguments contain the equivalent of:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
-a :80 -f /etc/varnish/default.vcl

Do not remove unrelated arguments merely to add these two settings. If your distribution already supplies a configuration file or environment variable for the listener, use that supported mechanism instead.

5. Apply the unit and VCL changes

When a systemd unit or drop-in has changed, make systemd reread it before restarting Varnish:

sudo systemctl daemon-reload
sudo systemctl restart varnish

If only the VCL changed, a restart is the simplest way to compile and load it. A VCL reload is also required after changing a hostname’s DNS address because name resolution happens during VCL compilation.

Check both services immediately:

sudo systemctl status varnish apache2

A failed Varnish start usually includes a VCL syntax error or a listener conflict in the journal. Read the relevant log lines rather than repeatedly restarting:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo journalctl -u varnish -b --no-pager
sudo journalctl -u apache2 -b --no-pager

6. Verify listeners and request the public path

Use a socket inspection tool to see which process owns each port:

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
sudo ss -ltnp

You should see Varnish listening on port 80 and Apache listening on 8080. Then test both layers:

  1. Origin: request http://127.0.0.1:8080/, adding the correct Host header if necessary.
  2. Cache front end: request http://127.0.0.1/ or the server’s public hostname, which reaches port 80.
  3. Compare responses: check status, redirects, content, and any cache-related headers your configuration exposes.

These checks isolate failures. A working origin with a failed public request points to Varnish’s listener, VCL, or backend connection; a failed direct request points to Apache or the application.

Equivalent setup on RHEL-compatible systems

Install Varnish using the repository and distribution package workflow documented by Varnish Cache for your RHEL-compatible release. Keep the same architecture: Varnish owns port 80, Apache owns 8080, and the VCL backend names the address and port where Apache actually listens.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Make the Apache edits under /etc/httpd. Update the active Listen directive from 80 to 8080 and change every enabled <VirtualHost *:80> binding to <VirtualHost *:8080>. Validate with the platform’s Apache configuration test, restart Apache, and test it directly before starting the cache.

Configure the Varnish systemd unit or a local override to use -a :80 and the intended VCL file. Run:

sudo systemctl daemon-reload
sudo systemctl restart varnish
sudo systemctl status varnish httpd
sudo ss -ltnp

The command names differ (httpd instead of apache2), but the diagnostic order is identical: verify Apache on 8080, verify Varnish on 80, then test through port 80.

Choose the right topology

Deployment choice What changes Important decision
Same host Varnish on 80 and Apache on 8080, commonly via loopback Use a local address and restrict the origin port from external access.
Separate origin host VCL points to the origin server’s reachable address and port Permit only the required network path and account for firewall rules, latency, and failure detection.
HTTP only Varnish terminates the public HTTP connection Port 80 is sufficient; do not assume this provides HTTPS.
TLS terminated by another proxy A TLS-capable load balancer or reverse proxy sits before Varnish Preserve the original host and scheme headers according to your proxy design, and decide where redirects and certificates are managed.
Single backend One backend default entry Simplest routing and health model; a backend outage makes misses fail.
Clustered backends Multiple backends plus explicit routing, failover, or load balancing Define health checks, selection rules, session behavior, and what happens when one origin is unhealthy.
Package-managed unit Use the distribution’s supplied service configuration Preferred when supported because upgrades can preserve defaults.
Local systemd override Add a drop-in rather than modifying vendor files Keep the complete required command line and document the override for future administrators.
Numeric backend address VCL uses an IP address such as 127.0.0.1 No DNS lookup is needed for a same-host origin.
Hostname backend VCL uses a DNS name Convenient for movable origins, but reload VCL whenever DNS changes because resolution occurs at compile time.

Multiple backends are not a drop-in extension of the minimal configuration. They require deliberate routing and health-check decisions, especially for logged-in sessions, uploads, shopping carts, and other stateful requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why Varnish returns 503 and how to isolate it

Apache is not listening where VCL expects

The most common 503 cause is that Varnish cannot connect to its configured backend. Compare the VCL values with the actual socket:

sudo ss -ltnp | grep -E ':80|:8080'
curl -i http://127.0.0.1:8080/

If Apache listens on another address, change .host. If it listens on another port, change .port. Restart or reload Varnish after editing the VCL so the new backend is compiled.

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.

Apache still owns port 80

Varnish cannot bind to port 80 while Apache does. Search all active Apache configuration for Listen 80 and <VirtualHost *:80>, including included files and enabled sites. Move every relevant binding to 8080, validate Apache, restart it, and then restart Varnish.

A unit edit appears to be ignored

Systemd caches unit definitions. After changing a service file or drop-in, run:

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.
sudo systemctl daemon-reload
sudo systemctl restart varnish

Use systemctl cat varnish to confirm which vendor unit and overrides are actually active. If the listener remains wrong, inspect the final ExecStart and any environment file referenced by the unit.

A hostname backend points to an old address

Varnish resolves a hostname when it compiles the VCL, not for every request. After DNS changes, reload the VCL or restart Varnish. Confirm the new destination independently with a direct connection and verify that firewalls allow it.

Only one virtual host fails

If the default site works but a named site does not, send the intended Host header to Apache on 8080. Then inspect apachectl -S (or the equivalent RHEL command) for duplicate, missing, or incorrectly ported virtual-host definitions. Varnish forwards the request host, but Apache can select a different site if the binding or name is incomplete.

Operational checks after the first successful request

  • Confirm both services are enabled as intended for the next boot, using your distribution’s normal systemctl enable policy.
  • Keep Apache’s origin port private on a same-host installation unless another trusted component must reach it.
  • Document which component terminates TLS, where redirects are generated, and which headers identify the original scheme and client.
  • Test cacheable and non-cacheable paths separately. Authentication, cookies, personalized pages, and unsafe methods often need explicit VCL rules rather than the minimal backend declaration.
  • After package upgrades, recheck the effective Varnish unit, VCL syntax, listeners, and a direct origin request. Distribution packages can change service defaults.
  • Monitor service logs and your own response metrics. No universal cache-hit or latency figure applies to every Apache application; measure hit rate, origin load, errors, and response time in the target deployment.

Safe rollback

If the public site fails after introducing Varnish, isolate the fault rather than changing several layers at once. First test Apache directly on 8080. If Apache is healthy, stop or reconfigure Varnish and temporarily expose Apache on port 80 by reversing the listener and virtual-host edits. Validate Apache, then decide whether to correct the VCL, unit, or network path before putting the cache back in front.

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

Keep a copy of the original Apache port configuration and the previous Varnish unit or drop-in. Rollback still requires a consistent pair: Apache must own 80 when Varnish is removed, and every enabled virtual host must use the matching port.

Configuration checklist

  • Varnish package installed from the operating system’s supported source.
  • Apache tested directly before caching.
  • /etc/apache2/ports.conf (or the RHEL equivalent) uses Listen 8080.
  • Every enabled Apache virtual host uses *:8080.
  • /etc/varnish/default.vcl declares vcl 4.1; and the real Apache host and port.
  • The effective Varnish service listens on :80 and loads the intended VCL.
  • systemctl daemon-reload was run after unit or drop-in edits.
  • Varnish and Apache both report active status.
  • ss -ltnp shows Varnish on 80 and Apache on 8080.
  • Direct origin and public port-80 requests both return the expected site.

The Bottom Line

For a same-host installation, put Varnish on port 80, move every Apache listener and virtual host to 8080, point /etc/varnish/default.vcl at 127.0.0.1:8080, reload systemd after unit changes, and test Apache and Varnish separately. That sequence prevents port conflicts and makes a 503 diagnosable instead of mysterious.

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 *

Free tools Windows power users keep installed

One-click scans. No signup required.

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
Crashes, No Sound, or Screen Glitches?Free driver scan

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.