luci: update haproxy conf

This commit is contained in:
xiaorouji 2023-04-03 14:40:19 +08:00 committed by sbwml
parent 56c68dfda4
commit 0fff20c983
3 changed files with 13 additions and 8 deletions

View File

@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall PKG_NAME:=luci-app-passwall
PKG_VERSION:=4.62 PKG_VERSION:=4.62
PKG_RELEASE:=3 PKG_RELEASE:=4
PKG_CONFIG_DEPENDS:= \ PKG_CONFIG_DEPENDS:= \
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \ CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \

View File

@ -1224,7 +1224,7 @@ start_haproxy() {
[ "$(config_t_get global_haproxy balancing_enable 0)" != "1" ] && return [ "$(config_t_get global_haproxy balancing_enable 0)" != "1" ] && return
haproxy_path=${TMP_PATH}/haproxy haproxy_path=${TMP_PATH}/haproxy
haproxy_conf="config.cfg" haproxy_conf="config.cfg"
lua $APP_PATH/haproxy.lua -path ${haproxy_path} -conf ${haproxy_conf} lua $APP_PATH/haproxy.lua -path ${haproxy_path} -conf ${haproxy_conf} -dns ${LOCAL_DNS}
ln_run "$(first_type haproxy)" haproxy "/dev/null" -f "${haproxy_path}/${haproxy_conf}" ln_run "$(first_type haproxy)" haproxy "/dev/null" -f "${haproxy_path}/${haproxy_conf}"
} }

View File

@ -30,6 +30,7 @@ end
local var = api.get_args(arg) local var = api.get_args(arg)
local haproxy_path = var["-path"] local haproxy_path = var["-path"]
local haproxy_conf = var["-conf"] local haproxy_conf = var["-conf"]
local haproxy_dns = var["-dns"] or "119.29.29.29"
local health_check_type = uci:get(appname, "@global_haproxy[0]", "health_check_type") or "tcp" local health_check_type = uci:get(appname, "@global_haproxy[0]", "health_check_type") or "tcp"
local health_check_inter = uci:get(appname, "@global_haproxy[0]", "health_check_inter") or "10" local health_check_inter = uci:get(appname, "@global_haproxy[0]", "health_check_inter") or "10"
@ -43,11 +44,11 @@ local f_out = io.open(haproxy_file, "a")
local haproxy_config = [[ local haproxy_config = [[
global global
daemon
log 127.0.0.1 local2 log 127.0.0.1 local2
maxconn 60000 maxconn 60000
stats socket %s/haproxy.sock stats socket %s/haproxy.sock
%s %s
daemon
defaults defaults
mode tcp mode tcp
@ -68,17 +69,17 @@ defaults
maxconn 3000 maxconn 3000
resolvers mydns resolvers mydns
nameserver dns1 127.0.0.1:53 nameserver dns1 %s:53
resolve_retries 3 resolve_retries 3
timeout retry 3s timeout retry 3s
hold valid 30s hold valid 600s
]] ]]
f_out:write(string.format(haproxy_config, haproxy_path, health_check_type == "passwall_logic" and string.format([[ f_out:write(string.format(haproxy_config, haproxy_path, health_check_type == "passwall_logic" and string.format([[
external-check external-check
insecure-fork-wanted insecure-fork-wanted
]]) or "" ]]) or "", haproxy_dns
)) ))
local listens = {} local listens = {}
@ -95,6 +96,8 @@ uci:foreach(appname, "haproxy_config", function(t)
server_remark = server_node.address .. ":" .. server_node.port server_remark = server_node.address .. ":" .. server_node.port
server_address = server_node.address server_address = server_node.address
server_port = server_node.port server_port = server_node.port
t.origin_address = server_address
t.origin_port = server_port
if health_check_type == "passwall_logic" then if health_check_type == "passwall_logic" then
if server_node.type ~= "Socks" then if server_node.type ~= "Socks" then
local relay_port = server_node.port local relay_port = server_node.port
@ -118,6 +121,8 @@ uci:foreach(appname, "haproxy_config", function(t)
else else
server_address, server_port = get_ip_port_from(lbss) server_address, server_port = get_ip_port_from(lbss)
server_remark = server_address .. ":" .. server_port server_remark = server_address .. ":" .. server_port
t.origin_address = server_address
t.origin_port = server_port
end end
if server_address and server_port and listen_port > 0 then if server_address and server_port and listen_port > 0 then
if not listens[listen_port] then if not listens[listen_port] then
@ -166,10 +171,10 @@ listen %s
]], remark, server, o.lbweight, health_check_inter, o.backup == "1" and "backup" or "")) ]], remark, server, o.lbweight, health_check_inter, o.backup == "1" and "backup" or ""))
if o.export ~= "0" then if o.export ~= "0" then
sys.call(string.format("/usr/share/passwall/app.sh add_ip2route %s %s", o.server_address, o.export)) sys.call(string.format("/usr/share/passwall/app.sh add_ip2route %s %s", o.origin_address, o.export))
end end
log(string.format(" | - 出口节点:%s:%s权重%s", o.server_address, o.server_port, o.lbweight)) log(string.format(" | - 出口节点:%s:%s权重%s", o.origin_address, o.origin_port, o.lbweight))
end end
end end