Hi.

Am 02.12.2019 um 13:40 schrieb JWD:

I have read this article many times, but still can't figure out how to do?

I can't believe it as there is exact the solution you want in the example and 
doc.

Can you give any detail tips?

capture request header X-Forwarded-For len 15

This line does not log any request with no X-Forwarded-For.
http-request set-log-level silent if !{ hdr(X-Forwarded-For) -m found }

You can't define specific field to log or not, but you can define your own logformat.
The default format for http logs is documented here if you set "option httplog"
https://cbonte.github.io/haproxy-dconv/2.1/configuration.html#8.2.3

I strongly suggest to read the logging section in the documentation.
https://cbonte.github.io/haproxy-dconv/2.1/configuration.html#8

It would be nice to share the haproxy -vv output to know which version you use.

Regards
Aleks

Thanks.
--------------------------------------------------------------------------------
JWD
*From:* Aleksandar Lazic <mailto:al-hapr...@none.at>
*Date:* 2019-12-02 18:42
*To:* JWD <mailto:j...@163.com>; haproxy <mailto:haproxy@formilux.org>
*Subject:* Re: How to log %[hdr_ip(X-Forwarded-For,-1)]
Hi.
Am 02.12.2019 um 09:27 schrieb JWD:
 > Hi,all
 > I want to write %[hdr_ip(X-Forwarded-For,-1)] to log, how to do that?
 > And how to log it with [if] confition? Like set-header below:
 >      http-request set-header X-Client-IP %[hdr_ip(X-Forwarded-For,-1)] if !{ 
hdr(X-Client-IP) -m found } { hdr(X-Forwarded-For) -m found }
 >      http-request set-header X-Client-IP %[src] if !{ hdr(X-Client-IP) -m 
found } !{ hdr(X-Forwarded-For) -m found }
 > Can anyone help me? Thanks.
>
You can capture request header via the following setup.
https://cbonte.github.io/haproxy-dconv/2.1/configuration.html#4-capture%20request%20header
For logging can you use this statement.
https://cbonte.github.io/haproxy-dconv/2.1/configuration.html#4.2-http-request%20set-log-level
 > JWD
Regards
Aleks


Reply via email to