pfSense/HAProxy — Rewrite Backend URL Request to masquarade path

Hi Community, I was setting up my pfSense to proxy through web resources so I didn’t have to deal with updating firewall rules when…

pfSense/HAProxy — Rewrite Backend URL Request to masquarade path

Hi Community, I was setting up my pfSense to proxy through web resources so I didn’t have to deal with updating firewall rules when service change and allow internet and dns in general to the containers and vms in general.

To do this you have to do some rewrite rules in the backend server definition

Let’s split this rule up into its parts to understand it a bit more.

  • The “%[]” indicates a function to run, or more like “use this input in parameter one and process it through function defined in parameter two”
  • The “path” is the variable containing the current path used by the request
  • The “regsub” is the function using regex with function “s” to substitute input via regular expression
  • The Input expression for the substitute “/linux/epel/?” is the incoming path from the frontend to be matched, the “?” says everything after that is passed through
  • The Output expression for the substitute “/pub/epel/” is the path to rewrite to, so for example.
Request on Frontend: mirror.woehl.network/linux/epel/ Rewrite on Frontend to Backend Server: [dl.fedoraproject.org]/linux/epel/ Rewrite on Backend to new Path: dl.fedoraproject.org/[pub/epel/]

Originally published at https://www.pierewoehl.de on December 18, 2020.