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

Rewrite host address of backend server

Scheduled Pinned Locked Moved Cache/Proxy
2 Posts 2 Posters 844 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.
  • J
    jonathan.young
    last edited by Mar 22, 2023, 2:42 PM

    Hi,

    With HAProxy, I am trying to write a rule that changes the address like so:

    https://abc-test.example.com to http://def-test.example.com
    

    My frontend handles the https and I have an ACL that checks the URL starts with 'abc'. If so, it passes it to a backend:

    backend test_ipvANY
            mode                    http
            id                      126
            log                     global
            errorfile                       503 /var/etc/haproxy/errorfile_test_ipvANY_503_test
            timeout connect         30000
            timeout server          30000
            retries                 3
            acl                     sw_start        var(txn.txnhost) -m sub -i abc-
            http-request set-var(txn.txnhost) hdr(host)
            http-request set-uri %[req.hdr(host),regsub(abc-,def-,g)]  if  sw_start
            server                  xyz-test.example.com 10.1.102.24:80 id 127 check inter 1000
    

    Unfortunately, I get back the error:

    File Not Found
    
    URI: def-test.example.com
    Method: GET
    Arguments: 0
    

    Can anyone tell me where I am going wrong? I realise that my backend server address is not the same as the one set in http-request set-uri but then I can't add wildcards to the backend server so I just created a dummy. Am I going about this the right way?

    Thanks

    M 1 Reply Last reply Apr 10, 2023, 4:20 PM Reply Quote 0
    • M
      michmoor LAYER 8 Rebel Alliance @jonathan.young
      last edited by Apr 10, 2023, 4:20 PM

      @jonathan-young you need a redirection rule - http-request redirect along with a conditional i think would help.

      http-request redirect location def-test.example.com code 302 if { hdr(host) -i  abc-test.example.com
      

      Firewall: NetGate,Palo Alto-VM,Juniper SRX
      Routing: Juniper, Arista, Cisco
      Switching: Juniper, Arista, Cisco
      Wireless: Unifi, Aruba IAP
      JNCIP,CCNP Enterprise

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
        [[user:consent.lead]]
        [[user:consent.not_received]]