Haproxy lua http-response http-request buffer
2019-7-15 7:20:24
收藏:0
阅读:106
评论:1
以下是我的计划,
我在Haproxy中设立了一些错误页面,我希望在负载平衡器级别上控制错误页面。
我有多个后端(不同的域),我希望为每个后端(域)返回不同的错误页面。
错误页面的文件位于haproxy中,每个域有不同的目录。
我基于http-request主机头进行http-response处理,使用主机头可以选择要服务的错误页面。
我能够实现这样的目标,但当我为每个域发起并行请求时,haproxy开始在域之间混淆响应。
我分享lua和haproxy配置
global
debug
log /dev/log local0 debug
lua-load /root/error-page.lua
ndefaults
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 )
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

经过调试问题和阅读LUA文档,我发现我使用方法"txn.sf:req_fhdr("host")"从HTTP请求中提取的参数"header host"可能是一个单一值字符串,该字符串在HTTP响应之间是共享的。