Hi Shawn

If I read your question right then you wan to serve other content on
an error, say 404 as a not found,.

haproxy has the ability to serve either error files of its own or
use_server or use_backend on error as an ACL

Below is an example error file and these need to be crafted, ill add a
link to them at the end


frontend www
    ...
    default_backend nomatch

backend nomatch
    errorfile 503 /var/www/http/404.http


OR you an use an ACL to get a similar result

frontend www
  ...
  default_backend no-match

backend no-match
  mode http
  http-request deny deny_status 400


http://cbonte.github.io/haproxy-dconv/1.9/configuration.html#4-http-request


Now the unknown host header,, you want this.com and the user requests
that.com and now what do we do? add a host header? reject by host
header

ill request a serverfault page for that and ask your forgiveness here
for not typing it all out for you ;) someone already did that for me
below

https://serverfault.com/questions/876871/configure-haproxy-to-include-host-headers-for-different-backends

Here at loadbalancer.org we have also been asked of a way to send the
host header as the real server label/name to the backend, this may
also work for you

listen example_vs
    bind 172.31.31.103:80 transparent
    id 680753459
    mode http
    **http-send-name-header Host**
    balance leastconn
    cookie SERVERID maxidle 30m maxlife 12h insert secure attr
"SameSite=None" attr "HttpOnly" nocache indirect
    server backup 127.0.0.1:9081 backup  non-stick
    option http-keep-alive
    timeout http-request 5s
    option forwardfor
    timeout tunnel 1h
    option redispatch
    option abortonclose
    maxconn 40000
    server **host.loadbalancer.org** 172.31.31.103:80 id 1387952112
weight 100  cookie host.loadbalancer.org  check port 80 inter 4000
rise 2  fall 2  slowstart 8000 minconn 0  maxconn 0  on-marked-down
shutdown-sessions


Where I added ** ** this shows where haproxy gets the hostname and
sends to host.loadbalancer.org with that hostname.

Now the custom error files, haproxy has a wonderful page which shows
how to do these

https://www.haproxy.com/blog/serve-dynamic-custom-error-pages-with-haproxy/

If I missed anything or if you have any further questions do not hesitate to ask



Andruw Smalley

Loadbalancer.org Ltd.

www.loadbalancer.org

+1 888 867 9504 / +44 (0)330 380 1064
[email protected]

Leave a Review | Deployment Guides|Blog

Andruw Smalley

Loadbalancer.org Ltd.

www.loadbalancer.org

+1 888 867 9504 / +44 (0)330 380 1064
[email protected]

Leave a Review | Deployment Guides|Blog



On Sat, 26 Mar 2022 at 23:50, Shawn Heisey <[email protected]> wrote:
>
> I would like to do a specific kind of 404 handling.  I did look for a
> way to do this before asking here.  I bet it's out there, I just haven't
> found the right search keywords.
>
> I have a virtualhost in Apache ... it is the first virtualhost in
> /etc/apache2/sites-enabled, configured without ServerName or ServerAlias
> so it is the default virtualhost that handles any hostname that is not
> specified in another virtualhost.  If somebody types an incorrect
> hostname in a URL that happens to point at my server, Apache gives them
> my 404 page, without changing the URL they entered.  Examples:
>
> https://unknown.elyograg.org/
> https://rand.elyograg.org/
> https://mickeymouse.elyograg.org/donaldduck
>
> I have 404 handling in Apache as well, so if an invalid URL path is
> specified on a valid hostname, they also get that page.  But in those
> cases, it is accomplished with a redirect to
> https://unknown.elyograg.org, so the URL changes in the user's browser.
>
> I would like to make it so that the presentation of the 404 page is
> always seamless, not a redirect.
>
> I have haproxy in front of all my websites, and various things including
> Apache 2.4 on port 81 behind that.  Can haproxy do what I'm after?  Can
> Apache?  Can it be accomplished with some combination of configs in both?
>
> Thanks,
> Shawn
>
>

Reply via email to