Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 Scan×
Skip to content
VGSources
Blog

How to Pass the Real Client IP From Varnish to Apache

Use Varnish's X-Forwarded-For forwarding with Apache mod_remoteip, trust only known Varnish addresses, and verify the effective and raw client IP values end to end.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass the address in X-Forwarded-For, then let Apache’s mod_remoteip turn that trusted value into the request’s effective client address. Varnish adds its client.ip to the header sent to a backend; Apache must be configured to accept that header only from your Varnish address or subnet.

The reliable sequence is: establish a trusted boundary in Varnish, configure Apache with RemoteIPHeader X-Forwarded-For and a narrow RemoteIPTrustedProxy list, then verify both the rewritten address and the original header in logs. Without the trust restriction, a visitor can forge the header and make Apache attribute a request to any address.

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 request path should look like

In a typical deployment, the browser connects to Varnish and Varnish connects to Apache:

Visitor  →  Varnish  →  Apache

Apache’s TCP peer is Varnish, so a normal access log initially records the Varnish address. The visitor’s address is carried separately in X-Forwarded-For. When Varnish receives a direct TCP connection from the visitor, client.ip is that connection peer. If another proxy terminates TLS or sends the PROXY protocol before Varnish, Varnish can instead populate client.ip from the original-client information supplied by that upstream hop.

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

The header is not inherently trustworthy. Every proxy that can write it must be under your control, and Apache must know which addresses are allowed to make the preceding address in the chain authoritative. Treat the header as ordinary client input until it has crossed that trust boundary.

How Varnish forwards the address

Built-in forwarding for ordinary HTTP

Current Varnish automatically appends the value of client.ip to the X-Forwarded-For request header sent to a backend. If an incoming request has no header, the resulting value contains the connection address. If a trusted upstream has already supplied a chain, Varnish adds its own peer address to that chain.

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

This built-in behavior means you should not add a second manual append such as:

set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;

Adding that operation in addition to Varnish’s normal handling can duplicate an address. Inspect the header that actually reaches Apache rather than assuming a hand-written append is required.

Resetting an untrusted incoming header

At the first proxy you control, you may want to discard values supplied by the visitor and start a new chain. Use the overwrite only at that trusted boundary:

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;
sub vcl_recv {
    # Remove any client-supplied chain at the first trusted proxy.
    set req.http.X-Forwarded-For = client.ip;
}

The example deliberately replaces the incoming value; it does not trust a browser-supplied address. Keep Varnish’s built-in forwarding behavior and do not add another manual append block. After deploying, capture the backend request or log the header at Apache to confirm that the resulting chain has the entries you expect for your Varnish version and VCL flow.

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

When an upstream proxy is in front of Varnish

If a load balancer or TLS terminator connects to Varnish using the PROXY protocol, configure the Varnish listener and the upstream device for the same protocol. Varnish can then set client.ip from the original-client metadata rather than from the load balancer’s socket address. The protocol must be enabled consistently on both ends; sending PROXY data to a listener that expects plain HTTP, or omitting it when the listener requires it, prevents a valid HTTP request from being parsed.

Configure Apache to use the forwarded address

1. Load mod_remoteip

Enable Apache’s mod_remoteip using the module-loading mechanism provided by your operating-system distribution. Do not assume that installing Apache also enabled this module. Confirm it is loaded before testing the address rewrite.

2. Select the forwarding header

Add the following directives in the server or virtual-host configuration that receives traffic from Varnish:

RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 192.0.2.10

192.0.2.10 is documentation-only example space. Replace it with the actual source address Apache sees for Varnish. If Varnish connects from more than one stable address, add each trusted address as appropriate. For a maintained set of addresses, use Apache’s RemoteIPTrustedProxyList directive and point it at a file containing the Varnish addresses or trusted subnets.

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

The critical control is RemoteIPTrustedProxy (or its list form). It tells Apache which immediate peers are allowed to advertise a different client address. Keep this set narrow and update it whenever Varnish’s egress addresses change. Do not authorize an entire broad network merely because it is convenient.

3. Understand Apache’s chain processing

Apache processes a comma-delimited X-Forwarded-For chain from right to left. It starts with the address of the connecting peer, checks whether that peer is trusted, and then evaluates the forwarded entries. Processing stops at the first address that is not trusted to present the address before it. This prevents an arbitrary leftmost value from automatically becoming the client address.

For example, a chain might contain several proxy hops followed by a visitor address. Apache’s effective address is the first untrusted hop encountered while walking from the Varnish side toward the left. The exact result depends on which proxy addresses you have placed in the trusted set; it is not determined simply by choosing the leftmost value.

Log both the effective address and the raw chain

During rollout, retain evidence of what Apache received and what mod_remoteip selected. Apache’s %a log token records the effective remote address after the module has rewritten it. The request-header expression %{X-Forwarded-For}i records the raw header, which can contain multiple addresses.

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

A temporary combined log format can include both fields:

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
LogFormat "%h %l %u %t "%r" %>s %b effective=%a xff="%{X-Forwarded-For}i"" forwarded
CustomLog logs/forwarded_access.log forwarded

Use the format supported by your Apache version and distribution. Keep the raw-header field for diagnosis, not as a substitute for the effective address in application authorization decisions. Once the path is proven, decide whether retaining the raw chain is appropriate for your privacy and logging policies.

Verification procedure

Test the complete path instead of checking only one configuration file. Run the following checks in order.

  1. Confirm the Varnish source as seen by Apache. Inspect the TCP peer in the Apache connection details or an initial log line. Use that address in RemoteIPTrustedProxy; the example address in documentation is not a production value.
  2. Capture the backend request. Use a request capture on the Varnish-to-Apache interface, or temporarily expose the header in a controlled Apache log. Verify that X-Forwarded-For is present and that Varnish’s own address appears where your topology predicts.
  3. Verify the module rewrite. Send a request from a known test client and confirm that the application and Apache’s %a field see that client address rather than the Varnish peer.
  4. Compare both log fields. Check the effective %a value against %{X-Forwarded-For}i. A mismatch can be correct when Apache stops at an untrusted hop; investigate the trust list and hop order before changing it.
  5. Test header forgery. Send a request from an untrusted client with a deliberately false X-Forwarded-For value. At the first trusted Varnish boundary, verify that the supplied chain is replaced when your policy requires it. Apache must not accept the forged value as the client address.
  6. Test every ingress path. Exercise direct Varnish traffic, each load-balancer path, IPv4 and IPv6 where enabled, and any health-check or administrative listener that can reach Apache. Each path needs an intentional trust decision.
  7. Retest after restarts and address changes. Reload Varnish and Apache in a maintenance window, then repeat the known-client and forged-header tests. A stale trusted-proxy list can silently change the meaning of the address.

HTTP forwarding versus PROXY protocol

These mechanisms solve related but different parts of the problem. X-Forwarded-For is an HTTP header that travels inside the request. PROXY protocol is connection metadata exchanged before the HTTP request, allowing Varnish to learn the original address from an upstream proxy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Aspect HTTP X-Forwarded-For PROXY protocol to Varnish
Where the original address comes from The header assembled by the proxy chain; Varnish contributes its client.ip. Original-client metadata supplied by the upstream load balancer or TLS terminator.
Transport requirement Works over an ordinary HTTP connection between Varnish and Apache. Both ends of the upstream connection must be configured for the PROXY protocol.
Boundary that must be trusted The first controlled proxy should remove or replace client-supplied values when necessary; Apache trusts only Varnish addresses. Varnish must trust the sender of the PROXY metadata, and Apache still trusts only the Varnish hop for the HTTP header.
Maintenance focus Keep Apache’s trusted Varnish addresses and any upstream header policy current. Keep the PROXY listener settings, upstream source addresses, and Apache’s Varnish trust list synchronized.

PROXY protocol does not remove the need for Apache’s mod_remoteip configuration. It supplies the value that Varnish uses as client.ip; Varnish still forwards that identity to Apache through the configured HTTP path.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Security rules for forwarded addresses

Trust the hop, not the claim

An X-Forwarded-For value is authoritative only when every hop that can write it is trusted. A client can set the header arbitrarily when connecting directly to a proxy that merely passes it through. Reset the header at the first boundary you control if the incoming chain is not authenticated or otherwise trusted.

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.

Keep the Apache allow-list narrow

List only the Varnish addresses or subnets that actually connect to Apache. Review the list when you add a node, change a network interface, move between address families, or introduce another proxy tier. A broad trust range allows an unintended host to impersonate a proxy.

Do not use the leftmost value blindly

Attackers commonly place a plausible address at the left edge of a forged chain. Apache’s right-to-left processing is designed to stop at the first untrusted hop, so preserve that behavior by configuring the trusted set accurately rather than extracting the first comma-separated value in application code.

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

Separate observability from authorization

Use the rewritten address for rate limits, audit context, and application logs only after the proxy path is controlled. If the same server is reachable both through Varnish and directly, configure the direct path separately; otherwise a request that bypasses the trusted boundary can be interpreted differently from one arriving through Varnish.

Troubleshooting by symptom

Apache still logs the Varnish address

  • Check that mod_remoteip is loaded and that Apache accepted the configuration reload.
  • Verify the directive spelling and that RemoteIPHeader X-Forwarded-For is in the active virtual host or server context.
  • Confirm that the address Apache sees for Varnish exactly matches a RemoteIPTrustedProxy entry, including IPv4 versus IPv6.
  • Inspect the raw header. If it is absent, the problem is between Varnish and Apache rather than in the rewrite module.

The application sees an unexpected intermediate address

  • Read the complete comma-delimited chain, not only its first value.
  • Walk the chain from right to left and compare each hop with Apache’s trusted list.
  • Remove stale or over-broad trust entries, then retest with a known client.

The address appears twice

  • Search the VCL for a manual append of client.ip.
  • Remove the extra append if Varnish’s built-in forwarding already adds the value.
  • If you overwrite the header at the trusted boundary, capture the final backend request after the VCL and built-in processing have run; do not infer the result from the assignment alone.

Requests fail after enabling PROXY protocol

  • Ensure the upstream sender and Varnish listener agree on whether PROXY protocol is enabled.
  • Do not send PROXY metadata to a plain-HTTP listener.
  • Check that the listener receiving the connection is the one configured for the protocol and that the upstream device is actually sending the original-client record.

Forged values still reach the application

  • Find the first proxy that accepts traffic from an untrusted client and reset the header there.
  • Check for alternate routes that bypass that proxy and connect directly to Apache or to a less-restricted Varnish listener.
  • Verify the test with both the raw header and the effective %a field; a raw forged value may remain visible for diagnostics while Apache correctly refuses to use it.

Deployment checklist

  • Map every hop from the client to Varnish and from Varnish to Apache.
  • Decide whether an upstream proxy’s address is supplied through ordinary HTTP headers or PROXY protocol.
  • At the first trusted boundary, replace an untrusted incoming X-Forwarded-For chain when your policy requires it.
  • Leave Varnish’s automatic append behavior in place and avoid a second manual append.
  • Enable Apache’s mod_remoteip.
  • Set RemoteIPHeader X-Forwarded-For.
  • Allow only the actual Varnish source addresses with RemoteIPTrustedProxy or RemoteIPTrustedProxyList.
  • Temporarily log both %a and %{X-Forwarded-For}i.
  • Test a known client, a forged header, each ingress path, and any PROXY-protocol listener.
  • Document who owns updates when Varnish addresses or upstream proxy settings change.

Operational guidance

Forwarded-IP configuration is part of the network trust model, not merely a logging preference. Keep a small topology diagram with the Varnish egress addresses, Apache listeners, and any upstream load balancer. When infrastructure changes, update the diagram and the Apache trust list together.

Keep diagnostic logging long enough to establish that the effective address, raw chain, and application-visible value agree. Then reduce exposure of raw headers according to your retention policy. The effective address is the value Apache selected after applying trust rules; the raw chain is evidence for troubleshooting and may contain information from multiple networks.

If you cannot make the proxy chain stable or maintain its addresses, have the team operating the managed proxy provide the exact source ranges and header or PROXY-protocol behavior. Apache still needs an explicit, reviewable trust boundary even when another party operates Varnish.

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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.