• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

hAproxy hands over client IP to apache2 logs [SOLVED]

Scheduled Pinned Locked Moved Cache/Proxy
16 Posts 4 Posters 2.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N
    noplan @Derelict
    last edited by Aug 16, 2020, 11:16 AM

    @Derelict

    yes done that already before the post
    now checked again and added

    Advanced pass thru
    http-request set-header X-Client-IP %[req.hdr_ip(X-Forwarded-For)]

    now checking again.
    brNP

    V 1 Reply Last reply Aug 17, 2020, 3:08 PM Reply Quote 0
    • V
      viragomann @noplan
      last edited by Aug 17, 2020, 3:08 PM

      @noplan
      What you're looking for is called "transparent proxy mode".

      You can enable it in the backend advanced settings: Transparent ClientIP.

      1 Reply Last reply Reply Quote 0
      • D
        Derelict LAYER 8 Netgate
        last edited by Aug 17, 2020, 3:12 PM

        Transparent proxy mode is a hack. I would avoid it.

        Chattanooga, Tennessee, USA
        A comprehensive network diagram is worth 10,000 words and 15 conference calls.
        DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
        Do Not Chat For Help! NO_WAN_EGRESS(TM)

        V N 2 Replies Last reply Aug 17, 2020, 5:55 PM Reply Quote 0
        • V
          viragomann @Derelict
          last edited by Aug 17, 2020, 5:55 PM

          @Derelict
          What exactly is the drawback of the transparent mode?

          I'm evaluating HAProxy for my purposes these days and did some tests so far.
          The impossibility to distinguish the origin clients IP was a thing which was bothering me. And I had also no luck with the forwardfor option.

          However, in the meantime I found that the webservers do not take over the clients IP into the log by default, though forwardfor is enabled. The websers logging need to be configured to do that.

          N D 2 Replies Last reply Aug 17, 2020, 6:46 PM Reply Quote 0
          • N
            noplan @Derelict
            last edited by Aug 17, 2020, 6:44 PM

            @Derelict

            same here. not gonna use it.

            1 Reply Last reply Reply Quote 0
            • N
              noplan @viragomann
              last edited by Aug 17, 2020, 6:46 PM

              @viragomann

              The websers logging need to be configured to do that.

              true ... any luck ?
              and what option on HAproxy did u use ?

              V 1 Reply Last reply Aug 17, 2020, 6:49 PM Reply Quote 0
              • V
                viragomann @noplan
                last edited by Aug 17, 2020, 6:49 PM

                @noplan
                I needed to add

                %{X-Forwarded-For}i
                

                to the log format config (mod_log_config.conf).

                N 1 Reply Last reply Aug 17, 2020, 7:11 PM Reply Quote 0
                • N
                  noplan @viragomann
                  last edited by Aug 17, 2020, 7:11 PM

                  @viragomann

                  thx
                  im gonna try this asap

                  1 Reply Last reply Reply Quote 0
                  • D
                    Derelict LAYER 8 Netgate @viragomann
                    last edited by Aug 17, 2020, 7:23 PM

                    @viragomann

                    @viragomann said in hAproxy hands over client IP to apache2 logs:

                    @Derelict
                    What exactly is the drawback of the transparent mode?

                    I'm evaluating HAProxy for my purposes these days and did some tests so far.
                    The impossibility to distinguish the origin clients IP was a thing which was bothering me. And I had also no luck with the forwardfor option.

                    However, in the meantime I found that the webservers do not take over the clients IP into the log by default, though forwardfor is enabled. The websers logging need to be configured to do that.

                    It tries to warn you in the GUI. I have seen it break other things in weird, hard-to-diagnose ways.

                    WARNING Activating this option will load rules in IPFW and might interfere with CaptivePortal and possibly other services due to the way server return traffic must be 'captured' with a automatically created fwd rule. This also breaks directly accessing the (web)server on the ports configured above. Also a automatic sloppy pf rule is made to allow HAProxy to server traffic.
                    Workaround exists only by configuring a second port or IP on the destination server for direct access of the website.
                    Having this option enabled also means that a client on the same subnet as the server wont be able to connect.
                    Use Client-IP to connect to backend servers. By default, failed health check are logged if server is UP and successful health checks are logged if server is DOWN, so the amount of additional information is limited.
                    Interface that will connect to the backend server. (this will generally be your LAN or OPT1(dmz) interface)
                    Connect transparently to the backend server's so the connection seams to come straight from the client ip address. To work properly this requires the reply traffic to pass through pfSense by means of correct routing.
                    When using IPv6 only routable ip addresses can be used, host names or link-local addresses (FE80) will not work.
                    (uses the option "source 0.0.0.0 usesrc clientip" or "source ipv6@ usesrc clientip")

                    Note : When this is enabled for any backend HAProxy will run as 'root' instead of chrooting to a lower privileged user, this reduces security in case a vulnerability is found.

                    Chattanooga, Tennessee, USA
                    A comprehensive network diagram is worth 10,000 words and 15 conference calls.
                    DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
                    Do Not Chat For Help! NO_WAN_EGRESS(TM)

                    1 Reply Last reply Reply Quote 1
                    • V
                      viragomann
                      last edited by Aug 18, 2020, 10:13 AM

                      @Derelict
                      I have read the warnings and hints, but I'm not able to evaluate the real drawbacks.

                      • CaptivePortal is not in use here.
                      • Accessing the webserver directly is still possible by split DNS and bypassing HAProxy.
                      • Slopy rule - don't know, what it really allows. The rule seems to be hidden.
                      • Running HAProxy as root - this is what I'm a bit worry about.

                      Anyway, since I've got it made to see the clients IP in the webservers log, there is no need for me to run HAProxy in transparent mode now.

                      1 Reply Last reply Reply Quote 0
                      • N
                        noplan
                        last edited by noplan Aug 26, 2020, 10:07 AM Aug 20, 2020, 2:20 PM

                        i m gonna mark this as solved

                        cuz first when u r able to read ;)

                        apache2.conf .... you find this

                        aea435f0-197a-4779-a95e-b98684906c0f-grafik.png

                        and second you put this in haProxy

                        b4c661d3-4f8f-4ab4-8b86-599f18b1f1b4-grafik.png
                        and (for the fun this)
                        0a532dc4-9423-4dfa-9207-6fdd584fd8d4-grafik.png

                        3b726d19-5356-4330-9491-412ed6e05c39-grafik.png
                        http-request set-header X-Client-IP %[req.hdr_ip(X-Forwarded-For)]

                        !!but be aware as @Derelict mentioned !!bd26226c-b163-44c7-9065-511e464b60fd-grafik.png

                        DONE DEAL !
                        thanx all for the help ... nP

                        V 1 Reply Last reply Aug 20, 2020, 2:34 PM Reply Quote 0
                        • V
                          viragomann @noplan
                          last edited by Aug 20, 2020, 2:34 PM

                          @noplan said in hAproxy hands over client IP to apache2 logs [SOLVED]:

                          and second you put this in haProxy

                          http-request set-header X-Client-IP %[req.hdr_ip(X-Forwarded-For)]

                          🙄
                          The X-Forward-For header option is just a simple checkbox in haproxy frontend settings as @Derelict illustrated above by a screenshot.

                          D 1 Reply Last reply Aug 20, 2020, 2:39 PM Reply Quote 0
                          • D
                            Derelict LAYER 8 Netgate @viragomann
                            last edited by Derelict Aug 20, 2020, 2:41 PM Aug 20, 2020, 2:39 PM

                            @viragomann said in hAproxy hands over client IP to apache2 logs [SOLVED]:

                            @noplan said in hAproxy hands over client IP to apache2 logs [SOLVED]:

                            and second you put this in haProxy

                            http-request set-header X-Client-IP %[req.hdr_ip(X-Forwarded-For)]

                            🙄
                            The X-Forward-For header option is just a simple checkbox in haproxy frontend settings as @Derelict illustrated above by a screenshot.

                            In the first reply to your question.

                            When you use advanced options like that you remove the ability of the pfSense developers to migrate your configuration as things change in the upstream package.

                            Chattanooga, Tennessee, USA
                            A comprehensive network diagram is worth 10,000 words and 15 conference calls.
                            DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
                            Do Not Chat For Help! NO_WAN_EGRESS(TM)

                            N 1 Reply Last reply Aug 26, 2020, 10:05 AM Reply Quote 0
                            • N
                              noplan @Derelict
                              last edited by Aug 26, 2020, 10:05 AM

                              @Derelict

                              i think not tested yet but on the toDo list
                              that the problem was that apache log format was not changed.

                              so that either the gui option nor the advanced option
                              was processed by apache
                              so next step is to check if its workin without advanced setting.
                              keep you posted NP

                              1 Reply Last reply Reply Quote 0
                              16 out of 16
                              • First post
                                16/16
                                Last post
                              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                                This community forum collects and processes your personal information.
                                consent.not_received