Logging the real client IP in IIS behind FortiWeb

When IIS sits behind a FortiWeb web application firewall in reverse proxy mode, your logs show FortiWeb's address instead of your visitors. FortiWeb can pass the client address in a header or preserve it at the connection level, and the documentation for the two modes does not fully agree. Here is what each setting does.

Short answer. In reverse proxy mode FortiWeb opens its own connection to IIS, so c-ip records the FortiWeb address. Fortinet's CLI reference lists x-forwarded-for-support and x-real-ip for FortiWeb, both disabled by default, and its Administration Guide says FortiWeb adds the source IP of the connection to X-Forwarded-For, appending to any existing list. Turn on Add X-Forwarded-For, then log the header as a column, as below, or validate it to correct c-ip itself.

To see the visitor in your log today, add the header as a custom column (elevated PowerShell):

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' `
  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" `
  -name "." `
  -value @{logFieldName='X-Forwarded-For';sourceName='X-Forwarded-For';sourceType='RequestHeader'}

It adds a cs(X-Forwarded-For) column and does not change c-ip. Only need the column? The free custom log field covers that, and the section below says where it stops being enough.

Which mode you run decides what IIS sees

ModeWhat Fortinet documents
Reverse proxyThe web server sees FortiWeb's IP address as the source of incoming requests. Add X-Forwarded-For applies here.
True transparent proxyFortinet's operation-mode page says the back-end server sees the client's original IP. Its X-Forwarded-For section lists this mode as applying source network address translation. The two statements conflict, so test a transparent deployment and send the header as well.
WCCPThe web server sees the FortiWeb network interface IP address, not the client's, as in reverse proxy mode.
Offline protectionWe could not confirm the source address IIS sees from Fortinet's pages. Check a live request.

The settings, and what they do

Add X-Forwarded-For and Add X-Real-IP sit under FortiWeb's X-Forwarded-For settings (CLI: config waf x-forwarded-for with set x-forwarded-for-support enable). Fortinet's 7.2 CLI reference gives the default for both as disabled, and its Administration Guide says they apply only in reverse proxy or true transparent proxy mode. Add X-Real-IP does not support IPv6. In current releases the guide also lists Delete Previous XFF Headers and Merge Previous XFF Headers (if both are enabled, Merge has no effect because Delete runs first); these are not in the 7.2 CLI reference, and Fortinet does not state which behaviour applies by default, so test whether a client-supplied value survives.

Client Real IP, in the server policy's network configuration, is the alternative that needs no header. Fortinet's 7.0 Administration Guide says FortiWeb then uses the source IP address of the client that originated the request, that it is available only in reverse proxy mode, and that it requires FortiWeb to be the server's gateway. It also notes it is unsupported when the backend is addressed by domain name rather than IP address, and advises against enabling it if the server's IP is used as the source address in a policy route. With it on, the connection IIS sees comes from the client, so c-ip is correct without a header.

Menu names and defaults change between FortiWeb releases; the versions cited here are 7.0, 7.2 and 8.0, so confirm against yours.

The fix: X-Forwarded-For for IIS

Winfrasoft X-Forwarded-For for IIS is an ISAPI web filter that reads the header FortiWeb adds and writes the real client address into the standard IIS c-ip log field, with no application changes and no change to FortiWeb's gateway arrangement. It suits estates that cannot or do not want to use Client Real IP.

Step by step

  1. Enable Add X-Forwarded-For on FortiWeb and log the header as a custom field to confirm what arrives, including whether a client-supplied value survives.
  2. Install the filter on the IIS servers behind FortiWeb.
  3. Populate the Proxy Trust List with the FortiWeb addresses that connect to IIS and every other internal hop.
  4. Close IIS to everything except FortiWeb at the firewall.
  5. Make a request through FortiWeb and confirm c-ip now holds the client address.

Is the free custom log field enough?

If all you need is the address somewhere in the log, IIS 8.5 and later can record the header as an extra column with no product, using the snippet at the top of this page. That appends a cs(X-Forwarded-For) column to the W3C log. It does not change c-ip.

It stops being enough when:

The click-through steps, and the log-file naming caveat, are in how to log X-Forwarded-For in IIS. If any of the points above applies, X-Forwarded-For for IIS 10 is the supported way to put the validated client address into c-ip itself.

Frequently asked questions

Does FortiWeb send X-Forwarded-For to IIS by default?

No. Fortinet's 7.2 CLI reference gives the default for x-forwarded-for-support and x-real-ip as disable, so IIS sees only FortiWeb's address until you turn Add X-Forwarded-For on.

What is Client Real IP in FortiWeb?

A server policy option that makes FortiWeb use the source IP address of the client that originated the request when it connects to the server. Fortinet says it is available only in reverse proxy mode and requires FortiWeb to be the server's gateway. IIS then logs the client directly in c-ip.

Does FortiWeb replace or append to an existing X-Forwarded-For?

Fortinet's Administration Guide says FortiWeb appends the source IP address to the header's list, and lists Delete Previous XFF Headers and Merge Previous XFF Headers options. Which applies by default we could not confirm, so test with a made-up value of your own.

Which addresses go in the Proxy Trust List for FortiWeb?

The addresses FortiWeb uses to connect to IIS, plus every other internal hop between FortiWeb and the server. In reverse proxy mode that is FortiWeb's own address on the server-facing side.

Get X-Forwarded-For for IIS

Log the real client IP in the standard IIS c-ip field behind FortiWeb, with a Proxy Trust List so the value is validated rather than merely copied. IIS 10 on Windows Server 2016–2025, with a free 14-day trial.

View the product   or request a download →

Stuck on your setup? Email us with your proxy and what c-ip shows, and we will take a look.