# Haproxy backend

**URL:** <https://discourse.haproxy.org/t/haproxy-backend/4912>\
**Category:** Help!\
**Created:** [February 28, 2020, 6:17pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912 "2020-02-28T18:17:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 6:17pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/1 "2020-02-28T18:17:54Z")

</div>

Hi

Can we have a haproxy.cfg without backend members , we want to use the hap solely for redirection only .

Please let me know if more info is needed…

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 6:47pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/2 "2020-02-28T18:47:53Z")

</div>

Absolutely.

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 6:54pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/3 "2020-02-28T18:54:04Z")

</div>

@lukastribus Could you please help me, of how we can do that, with an example syntax would be immensely helpful. Thanks in advance .

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 6:55pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/4 "2020-02-28T18:55:56Z")

</div>

Sure, just provide the current configuration you already have an I will make a suggestion.

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 7:13pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/5 "2020-02-28T19:13:59Z")

</div>

Yeah sure ,here iam trying to redirect [ab.com](http://ab.com) to [cd.com](http://cd.com) but would want it by bypassing the backend section

frontend http-in  
bind \*:8080  
mode http  
acl valid\_method method DELETE PUT GET POST OPTIONS PATCH  
http-request deny if ! valid\_method

```
acl url_ab url_beg /dum
acl url_ab_hdr hdr(host) -i [http://ab.com](http://ab.com/)
redirect prefix [http://cd.com](http://cd.com/) code 301 if { hdr(host) -i [http://ab.com](http://ab.com/) }
default_backend default_backend

```

backend default\_backend #not of any use  
balance roundrobin  
cookie SERVERID insert indirect nocache  
server workernode1 :9000 weight 1 maxconn 512 check cookie ab\_dum

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 7:30pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/6 "2020-02-28T19:30:45Z")

</div>

You’d remove the backend section, and the default\_backend directive pointing to that backend. Notice that the host header is not `http://ab.com/`, but `ab.com`.

```
frontend http-in
 bind *:8080
 mode http
 acl valid_method method DELETE PUT GET POST OPTIONS PATCH
 http-request deny if ! valid_method

 redirect prefix http://cd.com code 301 if { hdr(host) -i ab.com }
```

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 7:42pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/7 "2020-02-28T19:42:35Z")

</div>

yes, done. But when i remove them it throws a 503 service unavailable error ,rather than redirecting .

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 7:59pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/8 "2020-02-28T19:59:09Z")

</div>

Browsers probably include the port number here, seeing as this is a non-standard port 8080.

Try:

```
redirect prefix http://cd.com code 301 if { hdr(host) -i ab.com:8080 }
```

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 8:07pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/9 "2020-02-28T20:07:31Z")

</div>

Still no luck , stil throws a 503 service unavailable ☹

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 8:10pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/10 "2020-02-28T20:10:20Z")

</div>

Can you provide the output of a `curl -vv http://ab.com/` call?

Works fine for me:

```
$ curl -vv --resolve ab.com:8080:10.0.0.33 http://ab.com:8080/asdasd
* Added ab.com:8080:10.0.0.33 to DNS cache
* Hostname ab.com was found in DNS cache
* Trying 10.0.0.33...
* TCP_NODELAY set
* Connected to ab.com (10.0.0.33) port 8080 (#0)
> GET /asdasd HTTP/1.1
> Host: ab.com:8080
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< content-length: 0
< location: http://cd.com/asdasd
<
* Connection #0 to host ab.com left intact

$
```

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 8:25pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/11 "2020-02-28T20:25:08Z")

</div>

curl -vv [http://ab.com](http://ab.com)

- About to connect() to [ab.com](http://ab.com) port 80 (#0)

- Trying \<[ab.com](http://ab.com) ip\>…

- Connected to [ab.com](http://ab.com) \<[ab.com](http://ab.com) ip\>) port 80 (#0)

> GET / HTTP/1.1

> User-Agent: curl/7.29.0

> Host: [ab.com](http://ab.com)

> Accept: _/_

> 

- HTTP 1.0, assume close after body

\< HTTP/1.0 302 Found

\< Location: [https://ab.com/](https://ab.com/)

\< Server:

- HTTP/1.0 connection set to keep alive!

\< Connection: Keep-Alive

\< Content-Length: 0

\<

- Connection #0 to host [ab.com](http://ab.com) left intact

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [February 28, 2020, 8:26pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/12 "2020-02-28T20:26:46Z")

</div>

Strange , could you please share the exact config u had used ?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 28, 2020, 8:42pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/13 "2020-02-28T20:42:16Z")

</div>

What you are showing here does not match with what you configured and what you explained. Is haproxy running on port 8080 or not? Because you are pointing curl to a service on port 80, not 8080. Also it is redirecting to https on the standard port, not returning a 503 error as you said.

So I’m not sure what happens.

The configuration I use is:

```
frontend http-in
 bind *:8080
 mode http
 acl valid_method method DELETE PUT GET POST OPTIONS PATCH
 http-request deny if ! valid_method

 redirect prefix http://cd.com code 301 if { hdr(host) -i ab.com:8080 }

```

And I’m running curl against it (destination IP is 10.0.0.33):

```
curl -vv --resolve ab.com:8080:10.0.0.33 http://ab.com:8080/asdasd
```

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [March 2, 2020, 11:11am UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/14 "2020-03-02T11:11:41Z")

</div>

What we are trying to do is that, we have an LB that is listening at port (say 9000) and we have hap as docker container ,that when initialized is mapped as -p 8080:9000 ,  
so user req hits the lb at 80 request moves via 9000 to 8080 hap inturn to a backend (this is my understanding,correct me if iam wrong )  
now when iam trying to access the app at browser m getting a 503 ,but not in curl .

I have tried the exact config changing the port and everything ,still no luck.

Would you be having any active implementation of such a scenario ,that i can take a reference of ?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [March 2, 2020, 11:38am UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/15 "2020-03-02T11:38:15Z")

</div>

There is no point in looking at other haproxy configurtions or implementations. The above configuration works.

You need to troubleshoot the problem, understand what host header arrives at haproxy to be able to match the correct one, and understand where exactly the 503 error is coming from.

For example: in your browser open the developer tools (F12 in most browser) and review all the request and responses. Also enable haproxy logging and compare with the dev tools informations.

If you want to exclude the host header match for now, just redirect unconditionally (be removing the ACL condition):

```
redirect prefix http://cd.com code 301
```

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [March 3, 2020, 8:01pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/16 "2020-03-03T20:01:03Z")

</div>

The redirect is working perfectly for  
**redirect prefix [https://cd.com](https://cd.com) code 301**

But however when i add the if condition  
**redirect prefix [https://cd.com](https://cd.com) code 301 if { hdr(host) -i [https://ab.com:8080](https://ab.com:8080) }** or  
**redirect prefix [https://cd.com](https://cd.com) code 301 if { url\_beg /abc }**

it returns a 503 denoting failure of redirection as the redirection rule itself is not being processed ( doesnt make sense for hap) .

The HAP log shows http\_request:GET /abc HTTP/1.1 with termination state as SC

Ps:503 is the default output that [ab.com](http://ab.com) gives when no hap redirect is configured

Please let me know any suggestions wrt this ?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [March 3, 2020, 8:04pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/17 "2020-03-03T20:04:18Z")

</div>

The ACL does not match. You need to know what’s in the Host header to write a rule matching that host header.

What are you literally writing in the address bar of the browser _EXACTLY_ when accessing haproxy, expecting the redirect?

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [March 3, 2020, 8:10pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/18 "2020-03-03T20:10:11Z")

</div>

We input [https://ab.com/abc](https://ab.com/abc)  
(this is hypothetical urls nd context resembling the real scenario ),

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [March 3, 2020, 8:14pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/19 "2020-03-03T20:14:57Z")

</div>

In that case you did not tell me the whole story, because your haproxy is not configured for TLS termination.

---

<div class="post-metadata">

**Author:** ![aarathy53](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aarathy53](https://discourse.haproxy.org/u/aarathy53)\
**Post date:** [March 3, 2020, 8:19pm UTC](https://discourse.haproxy.org/t/haproxy-backend/4912/20 "2020-03-03T20:19:36Z")

</div>

What we are trying to do is that, we have an LB that is listening at port (say 9000 with [abc.com](http://abc.com)) and we have hap as docker container ,that when initialized is mapped as -p 8080:9000 ,  
so user req hits the lb at 80 request moves via 9000 to 8080 hap inturn to a backend . **SSL termination is handled at the f5 LB itself** and we would need the haproxy to solely take care of the redirection alone .

And right now we are trying for redirect of url to happen based on the context path as condition .

[Next page](https://discourse.haproxy.org/t/haproxy-backend/4912.md?page=2)
