Here's my plan,
I'm setting up some error-page in the Haproxy,I want to control the error pages at load-balancer level.
I've got multiple back-end (different domain), I want to give back a different error-page for each back-end (domain).
The error-page's file are located inside of the haproxy in different directory for each domain.
I'm processing the http-response based on the http-request host header, with the host header I can choose which error page to serve.
I was able to achieve such a objective but when I lunch parallel request for each domains the haproxy start to mix up the response between domains.
I share the lua and the haproxy config
global
debug
log /dev/log local0 debug
lua-load /root/error-page.lua
defaults
log global
mode http
retries 3
backlog 10000
maxconn 10000
timeout connect 3s
timeout client 30s
timeout server 180s
timeout tunnel 120s
timeout http-keep-alive 1s
timeout http-request 15s
timeout queue 30s
timeout tarpit 60s
option redispatch
option http-server-close
option dontlognull
option contstats
option forceclose
errorfile 404 /root/errors/404.http
errorfile 500 /root/errors/5xx.http
frontend http
bind *:80
acl error status ge 400
http-response lua.error-page if error
http-request lua.error-page
use_backend web
backend web
server web-1 10.93.3.41:1500 check
function file_check(file_name)
local file_found=io.open(file_name, "r")
if file_found==nil then
check = "file not found" .. file_name
else
check = "file found" .. file_name
local error_file2 = io.open(file_name, "r")
local file = error_file2:read("a*")
error_file2:close()
return file
end
end
function http_request_header(txn)
host = txn.sf:req_fhdr("host")
end
function http_response_header(txn)
local error_code = txn.sf:status()
local domain = "/root/errors/by-domains/" .. host .. "/error-" .. error_code .. ".html"
if file_check(domain) ~= nil then
error_page = file_check(domain)
error_path = domain
end
if error_page ~= nil then
txn:Debug("lua.error-page: rewrite error page: " .. error_path )
txn.res:set("")
txn.res:send(error_page)
txn.done(txn)
else
error_path = "back-end"
txn:Debug("lua.error-page: rewrite error page: " .. error_path )
end
end
core.register_action("error-page", { "http-res" }, http_response_header )
core.register_action("error-page", { "http-req" }, http_request_header )