2
votes

I'm trying to get haproxy to redirect to a new location if it receives a 404 response from a backend server. If it does not receive a 404, I would like it to respond normally.

This made sense to me, but doesn't seem to work:

frontend  front
    option httplog
    bind *:8080
    default_backend             app

backend app
    balance     roundrobin
    acl document_request path_beg -i /documents
    acl not_there status 404
    http-request redirect location http://newlocation/%[path] if document_request not_there
    server  webserver1 10.10.10.10:8080 check

I received the following warning:

acl 'not_there' will never match because it only involves keywords that are incompatible with 'backend http-request header rule'

I'm using version 1.5.14 on Centos 7.

Any ideas on how to make this work? Is it possible to do what I am trying to do?

Any assistance would be greatly appreciated.

Thanks,

AL

1

1 Answers

2
votes

http-request redirect redirects the request (optionally) based on a condition that inspects the request.

status can only inspect the response. 'incompatible with http-request header rule' means status is only compatible with http-response rules.

At the time you got the status code you can only rewrite its response. Try editing location and status with http-response set-header resp. set-status.

Since version 1.6 you can use http-response redirect.