Pieter Baauw | 06da4df | 2013-05-11 08:00:53 +0200 | [diff] [blame] | 1 | # |
| 2 | # This is an example of how to configure HAProxy to be used as a 'full transparent proxy' for a single backend server. |
| 3 | # |
| 4 | # Note that to actually make this work extra firewall/nat rules are required. |
| 5 | # Also HAProxy needs to be compiled with support for this, in HAProxy1.5-dev19 you can check if this is the case with "haproxy -vv". |
| 6 | # |
| 7 | |
| 8 | global |
| 9 | frontend MyFrontend |
| 10 | bind 192.168.1.22:80 |
| 11 | default_backend TransparentBack_http |
| 12 | |
| 13 | backend TransparentBack_http |
| 14 | mode http |
| 15 | source 0.0.0.0 usesrc client |
| 16 | server MyWebServer 192.168.0.40:80 |
| 17 | |
| 18 | # |
| 19 | # To create the the nat rules perform the following: |
| 20 | # |
| 21 | # ### (FreeBSD 8) ### |
| 22 | # --- Step 1 --- |
| 23 | # ipfw is needed to get 'reply traffic' back to the HAProxy process, this can be achieved by configuring a rule like this: |
| 24 | # fwd localhost tcp from 192.168.0.40 80 to any in recv em0 |
| 25 | # |
| 26 | # The following would be even better but this did not seam to work on the pfSense2.1 distribution of FreeBSD 8.3: |
| 27 | # fwd 127.0.0.1:80 tcp from any 80 to any in recv ${outside_iface} uid ${proxy_uid} |
| 28 | # |
| 29 | # If only 'pf' is currently used some aditional steps are needed to load and configure ipfw: |
| 30 | # You need to configure this to always run on startup: |
| 31 | # |
| 32 | # /sbin/kldload ipfw |
| 33 | # /sbin/sysctl net.inet.ip.pfil.inbound="pf" net.inet6.ip6.pfil.inbound="pf" net.inet.ip.pfil.outbound="pf" net.inet6.ip6.pfil.outbound="pf" |
| 34 | # /sbin/sysctl net.link.ether.ipfw=1 |
| 35 | # ipfw add 10 fwd localhost tcp from 192.168.0.40 80 to any in recv em0 |
| 36 | # |
| 37 | # the above does the folowing: |
| 38 | # - load the ipfw kernal module |
| 39 | # - set pf as the outer firewall to keep control of routing packets for example to route them to a non-default gateway |
| 40 | # - enable ipfw |
| 41 | # - set a rule to catches reply traffic on em0 comming from the webserver |
| 42 | # |
| 43 | # --- Step 2 --- |
| 44 | # To also make the client connection transparent its possible to redirect incomming requests to HAProxy with a pf rule: |
| 45 | # rdr on em1 proto tcp from any to 192.168.0.40 port 80 -> 192.168.1.22 |
| 46 | # here em1 is the interface that faces the clients, and traffic that is originally send straight to the webserver is redirected to HAProxy |
| 47 | # |
| 48 | # ### (FreeBSD 9) (OpenBSD 4.4) ### |
| 49 | # pf supports "divert-reply" which is probably better suited for the job above then ipfw.. |
| 50 | # |