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

    [RESOLVED] Request for help HAPROXY redirection to subdirectory.

    pfSense Packages
    3
    4
    4.7k
    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.
    • T
      Tueurdragon
      last edited by Tueurdragon

      Hello everyone,

      I allow myself to write to you, because I would need a little help.

      I am having difficulty setting up HAPROXY.

      Here is the context:
      I have an IIS web server that hosts multiple sites in subdirectories and I would like to use HAPROXY to rewrite URLs to the subdirectories.

      Example:
      https://test1.test.fr --> which would actually point on the backend 192.168.1.1 to the test1 subdirectory (http://192.168.1.1/test1/)
      https://test2.test.fr --> which would actually point on the same backend 192.168.1.1 to the test2 subdirectory http://192.168.1.1/test2/

      Can someone nice give me some info on the settings?

      Thank you very much,

      1 Reply Last reply Reply Quote 0
      • T
        Tueurdragon
        last edited by

        Hello everyone.

        After a few days of research, I managed to solve my problem.

        For information, here is how to perform the operation.

        In the FrontEnd part

        I added the following ACLs:

        ACL No. 1
        Name: Domain1
        Phrase: Host matches
        CS: no
        Note: no
        Value: test1.test.fr

        ACL No. 2
        Name: Domain2
        Phrase: Host matches
        CS: no
        Note: no
        Value: test2.test.fr

        ACL No. 3
        Name: SubPath
        Expression: Path matches
        CS: no
        Note: no
        Value: /

        I then added the following Actions:

        Action No. 1
        Action: Use Backend
        Parameters: See below
        Conditional acl names: Domain1
        Backend: (your backend name) ex: 192.168.1.1

        Action No. 2
        Action: http-request set path
        Parameters: See below
        Condition acl names: Domain1 Subpath
        fmt: /test1

        Action No. 3
        Action: Use Backend
        Parameters: See below
        Condition acl names: Domain2
        Backend: (your backend name) ex: 192.168.1.1

        Action No. 4
        Action: http-request set path
        Parameters: See below
        Condition acl names: Domain1 Subpath
        fmt: /test2

        Have a lovely day everybody.

        zecoraZ S 2 Replies Last reply Reply Quote 2
        • zecoraZ
          zecora @Tueurdragon
          last edited by

          @tueurdragon thank you for this. I'm new to HAProxy but I'm still having issues getting everything to work and cannot figure it out. How does the 'subpath' tie into a backend or do your servers use another reverse proxy? Has anything changed in your config or would you be able to post a generic config? Mine is listed below.

          # Automaticaly generated, dont edit manually.
          # Generated on:
          global
          	maxconn			500
          	stats socket /tmp/haproxy.socket level admin  expose-fd listeners
          	uid			80
          	gid			80
          	nbthread			1
          	hard-stop-after		15m
          	chroot				/tmp/haproxy_chroot
          	daemon
          	tune.ssl.default-dh-param	4096
          	server-state-file /tmp/haproxy_server_state
          
          listen HAProxyLocalStats
          	bind 127.0.0.1:2200 name localstats
          	mode http
          	stats enable
          	stats admin if TRUE
          	stats show-legends
          	stats uri /haproxy/haproxy_stats.php?haproxystats=1
          	timeout client 5000
          	timeout connect 5000
          	timeout server 5000
          
          frontend fe_HAProxy
          	bind			0.0.0.0:443 name 0.0.0.0:443   ssl crt-list /var/etc/haproxy/fe_HAProxy.crt_list  
          	mode			http
          	log			global
          	option			http-keep-alive
          	timeout client		30000
          	acl			fe_organizr	var(txn.txnhost) -m str -i organizr.domain.local
          	acl			fe_sonarr	var(txn.txnpath) -m str -i /
          	acl			aclcrt_fe_BBHAProxy	var(txn.txnhost) -m reg -i ^([^\.]*)\.domain\.local(:([0-9]){1,5})?$
          	http-request set-var(txn.txnhost) hdr(host)
          	http-request set-var(txn.txnpath) path
          	http-request set-path /sonarr  if  fe_organizr fe_sonarr aclcrt_fe_HAProxy
          	http-request  deny if { req.hdr_cnt(content-length) gt 1 }
          	http-response deny if { res.hdr_cnt(content-length) gt 1 }
          	use_backend be_organizr_ipvANY  if  fe_organizr aclcrt_fe_HAProxy
          
          backend be_organizr_ipvANY
          	mode			http
          	id			128
          	log			global
          	timeout connect		30000
          	timeout server		30000
          	retries			3
          	load-server-state-from-file	global
          	server			organizr 10.10.10.10:8006 id 129
          
          1 Reply Last reply Reply Quote 0
          • S
            sinapseredes @Tueurdragon
            last edited by

            @Tueurdragon Thanks!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.