DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk9 min

How to Pass the Real Client IP From Varnish to Apache

A practical guide to forwarding the visitor’s IP from Varnish to Apache, securing X-Forwarded-For against spoofing, configuring mod_remoteip, and validating the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass the address in X-Forwarded-For, then make Apache trust only the Varnish address (or its tightly controlled subnet) with mod_remoteip. Varnish adds its client.ip to the forwarding header for backend requests; Apache can then replace the connection peer address with the visitor’s address for applications and access logs.

The security boundary matters more than the header name. A client can send a forged X-Forwarded-For value, so remove or overwrite untrusted values at the first proxy you control and never configure Apache to trust arbitrary senders.

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.

How the address moves from the browser to Apache

Apache normally sees the TCP peer that connected to it. When Varnish is the reverse proxy, that peer is Varnish, so ordinary Apache logs show a Varnish address rather than the visitor. The visitor address travels separately in an HTTP request header.

For a direct client-to-Varnish connection, Varnish’s client.ip is the client’s connection address. Varnish forwards that value in X-Forwarded-For when it sends a request to the backend. Apache’s mod_remoteip reads the header and changes the request’s effective remote address, provided the immediate sender is a configured trusted proxy.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

A typical path looks like this:

  1. The browser connects to Varnish.
  2. Varnish determines client.ip and builds the forwarding header.
  3. Varnish connects to Apache and sends X-Forwarded-For.
  4. Apache verifies that the connection came from a trusted Varnish address.
  5. mod_remoteip evaluates the comma-separated chain from right to left and selects the first address that cannot be vouched for by a trusted proxy.
  6. Apache applications and the %a access-log field use the resulting effective client address.

If Varnish is behind another load balancer or TLS terminator, the first hop must also be configured correctly. With PROXY protocol, Varnish can receive original-client metadata from that upstream and use it when setting client.ip. Without PROXY protocol, Varnish sees the address of the upstream device as its connection peer.

Configure Varnish at the trusted boundary

Let current Varnish forwarding do the normal append

Current Varnish automatically appends client.ip to the X-Forwarded-For request header sent to a backend. You therefore do not need a second custom block whose only job is to append client.ip. Adding one can produce duplicate addresses and make the chain harder to interpret.

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

First determine whether clients can reach Varnish directly or whether another proxy is in front of it. That determines what client.ip means. If a trusted upstream speaks PROXY protocol, configure the Varnish listener for that protocol; if it does not, do not enable PROXY protocol merely because you want the original address.

Discard a client-supplied chain when Varnish is your first trusted proxy

Because an HTTP client can send any header, a public Varnish listener should not blindly preserve a client-provided X-Forwarded-For. At the first proxy you control, overwrite the header with the address Varnish obtained from the connection:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
vcl 4.1;

sub vcl_recv {
    # Remove any client-supplied chain at the first trusted proxy.
    set req.http.X-Forwarded-For = client.ip;
}

Use this overwrite only at a boundary you trust. It establishes a clean starting point instead of allowing an arbitrary leftmost value to enter your infrastructure. Keep Varnish’s normal forwarding behavior and do not add another manual append block elsewhere. After deployment, inspect the actual header received by Apache; custom VCL flow can otherwise result in a duplicated address.

When another trusted proxy is in front

If a load balancer, ingress proxy, or TLS terminator is already responsible for the original address, decide which device is authoritative. A common arrangement is for that device to send PROXY protocol to Varnish. Varnish then obtains the original address as connection metadata and forwards it to Apache through the normal HTTP header. If the upstream instead sends an HTTP forwarding chain, document which hop is allowed to add values and have Varnish reset the chain at the boundary you operate.

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

Configure Apache with mod_remoteip

Load the module

Enable Apache’s mod_remoteip using the module-loading mechanism supplied by your operating system. Package names and commands differ between distributions, so verify that the module is actually loaded rather than assuming that installing a package changed the running server.

After loading it, set the header Apache should interpret and identify the Varnish sender as trusted:

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 192.0.2.10

192.0.2.10 is documentation-only example space. Replace it with the real source address that Apache sees for Varnish. Do not copy that address into production.

Use a maintained list for more than one Varnish address

For a cluster, failover pair, or changing pool, use RemoteIPTrustedProxyList and maintain a file containing only the Varnish addresses or narrowly scoped trusted subnets. Treat changes to that file as security-sensitive configuration. A stale list can make legitimate traffic appear to come from Varnish, while an over-broad list can let an unintended host manufacture client addresses.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Directive Purpose Operational guidance
RemoteIPHeader X-Forwarded-For Tells Apache which request header carries the advertised client chain. Use the exact header name emitted by your proxy.
RemoteIPTrustedProxy address Trusts one Varnish address or subnet to present the preceding address. Keep entries limited to actual Varnish source addresses.
RemoteIPTrustedProxyList file Loads a maintained set of trusted proxy addresses. Update it whenever Varnish egress addresses change.

Understand Apache’s right-to-left processing

Apache processes a comma-delimited forwarding chain from right to left. It removes or walks through addresses presented by trusted proxies and stops when it reaches an address that is not trusted to present the preceding value. This prevents a client from gaining authority merely by placing a plausible address at the left edge of the header.

Do not solve a mismatch by adding every network in your environment to the trusted list. The list should describe the devices that are allowed to write the chain immediately before Apache. If a second proxy is legitimately part of the chain, add that specific proxy or subnet and verify the resulting order.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Verify the effective address and the raw chain

Roll out the change with temporary diagnostics. You need to see both what Apache decided to use and what the proxy actually sent.

  1. Confirm the module is active. Use your distribution’s Apache module listing or configuration test and verify that mod_remoteip is loaded. Correct syntax errors before restarting or reloading.
  2. Confirm the transport source. On the Apache host, identify the source address of the Varnish connection. Put that exact address, or the smallest appropriate subnet, in RemoteIPTrustedProxy.
  3. Capture the incoming header. Add a temporary access-log format that includes both %a and %{X-Forwarded-For}i. The first shows Apache’s effective remote address after rewriting; the second preserves the header Apache received, which can contain multiple addresses.
  4. Make a controlled request. Connect through the normal public path and compare the expected client address with the two logged values. Check an IPv4 client and, if your service supports it, an IPv6 client.
  5. Test an attempted forgery. Send a request containing your own X-Forwarded-For value from an untrusted client. The value should be removed or replaced at the Varnish boundary, not accepted as the visitor address.
  6. Test every ingress path. Repeat the check through each load balancer, health-check route, failover Varnish node, and direct-origin path. A path that bypasses the trusted proxy can produce a different result or expose the origin.
  7. Remove or restrict diagnostics. Raw forwarding headers can contain addresses from several internal hops. Keep the extra field only as long as needed for rollout, then return to the log format required by your privacy and retention policies.

Remember that a cache hit can be served by Varnish without a request reaching Apache. Apache access logs therefore describe requests that reached the origin, not necessarily every visitor request handled at the edge. Measure edge traffic separately if you need a complete visitor count.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

HTTP forwarding versus PROXY protocol

These mechanisms solve related but different parts of the problem. HTTP forwarding carries the address in an application-layer header; PROXY protocol carries connection metadata from one trusted transport hop to the next.

Aspect HTTP X-Forwarded-For PROXY protocol to Varnish
Where the original address comes from A proxy writes an HTTP request header, normally using its observed client address. An upstream device sends original-client metadata as part of the connection preamble.
Transport requirement Works over ordinary HTTP between Varnish and Apache. Both sides of the upstream connection must support and enable the same PROXY protocol version and listener mode.
Boundary that must reset or pass data The first trusted proxy should overwrite an untrusted client header or deliberately validate the chain. The device that emits PROXY protocol must be trusted, and Varnish must parse it on the correct listener.
Apache trust maintenance Apache trusts the Varnish source address or subnet through RemoteIPTrustedProxy or its list file. Apache still trusts Varnish; PROXY protocol changes how Varnish learns client.ip, not Apache’s trust requirement.

Never enable PROXY protocol on only one side. A listener expecting the protocol will interpret ordinary HTTP incorrectly, while a listener that does not expect it cannot safely consume the metadata. Confirm the upstream device, Varnish listener, and failover configuration as one change.

Security rules that prevent spoofing

Trust the writer, not the text

An IP address in a header is a claim. It becomes useful only when every hop that could have written it is trusted. Apache should trust the immediate Varnish connection, and Varnish should trust only the upstream device that supplies original-client metadata.

Protect the origin from direct access

If clients can connect directly to Apache, they can bypass the Varnish trust boundary and send requests that do not follow your intended policy. Restrict the origin firewall or network ACL so that production HTTP traffic arrives only through approved proxy addresses. Keep administrative and health-check exceptions explicit.

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.

Keep the chain narrow and observable

Do not assume the leftmost address is safe. Long chains usually indicate several proxies, a preserved client value, or a configuration error. Record the effective address and raw chain during changes, document each hop, and remove obsolete trusted ranges when infrastructure is retired.

Troubleshooting by symptom

Apache still logs the Varnish address

  • Check that mod_remoteip is loaded in the active Apache instance, not only installed on disk.
  • Verify the directive is in a configuration context Apache reads and that the service was reloaded successfully.
  • Compare Apache’s actual TCP peer with the value in RemoteIPTrustedProxy; a load balancer may make the peer different from the Varnish address you expected.
  • Confirm Varnish is sending X-Forwarded-For on the backend request and that an intermediate proxy is not removing it.

The address is wrong or contains a client-supplied value

  • Inspect the raw header at Apache and the header immediately before Varnish forwards it.
  • At the first trusted proxy, overwrite the incoming header with client.ip when no upstream proxy is authorized to supply a chain.
  • Check that the public client cannot reach Apache directly and that no broad trusted subnet includes untrusted hosts.

The same address appears twice

  • Search custom VCL for a manual append of client.ip in addition to Varnish’s current automatic behavior.
  • Review whether a custom vcl_recv path sets the header and then allows another append to run.
  • Inspect each upstream proxy so you know whether duplicate values are introduced before Varnish or between Varnish and Apache.

Every request fails when PROXY protocol is enabled

  • Verify that the upstream sender actually speaks PROXY protocol on that listener.
  • Confirm the protocol version and listener mode match on both ends.
  • Ensure ordinary health checks and any alternate upstream still use a listener configured for the protocol they send.

IPv6 clients appear inconsistent

  • Confirm that Varnish, Apache, firewalls, and log parsers all accept IPv6 addresses.
  • Use the exact IPv6 address or an intentionally scoped IPv6 subnet in the trusted-proxy configuration.
  • Compare the raw header with the effective %a value; do not normalize or truncate addresses in an intermediary log parser.

Safe rollout checklist

  • Map every hop from the client to Apache and identify which hop is authoritative for the original address.
  • Decide whether Varnish receives a direct TCP client connection, an HTTP forwarding chain, or PROXY protocol from an upstream device.
  • Reset untrusted X-Forwarded-For data at the first proxy you control.
  • Enable mod_remoteip and set RemoteIPHeader X-Forwarded-For.
  • Trust only the Varnish address or maintained Varnish subnet list in Apache.
  • Log %a and %{X-Forwarded-For}i temporarily while testing.
  • Test normal traffic, forged headers, cache hits, cache misses, failover nodes, IPv4, IPv6, and every alternate ingress route.
  • Remove duplicate VCL append logic and disable temporary raw-header logging after validation.
  • Review the trusted list whenever Varnish addresses, load balancers, or network boundaries change.

Complete minimal pattern

For a direct client-to-Varnish deployment, the essential pieces are a clean Varnish boundary and a narrowly scoped Apache trust rule:

vcl 4.1;

sub vcl_recv {
    # Replace a client-provided chain at the first trusted boundary.
    set req.http.X-Forwarded-For = client.ip;
}
# Load mod_remoteip using your distribution's normal mechanism.
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 192.0.2.10

Replace the example address, reload both services using your normal change procedure, and verify the effective address against the raw header before treating the result as authoritative in access control, auditing, rate limiting, or application data.

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.

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

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 from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
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.