问题原文
原帖链接 · Augustin · CC BY-SA 3.0
In Nginx we can return a specific status code to URL prefix like this.
location /api {
return 200;
}
How can we achieve the same in Haproxy?.
Gone through Haproxy ACL but couldn't find any.
已采纳解答
原帖链接 · DavidGamba · CC BY-SA 4.0
This can be accomplished by using a lua response script. I already use one to set the CORS headers for the preflight response.
My rule is the following:
global
...
lua-load /etc/haproxy/200.lua
frontend
bind ...
...
use_backend http_200 if ...
backend http_200
http-request use-service lua.200-response
Lua script in /etc/haproxy/200.lua:
# 200.lua
core.register_service("200-response", "http", function(applet)
local response = ""
applet:set_status(200)
applet:add_header("Content-Length", "0")
applet:start_response()
applet:send(response)
end)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
