在haproxy中使用环境变量 [英] use environment variables in haproxy

查看:264
本文介绍了在haproxy中使用环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人可以指出正确的方向。

Hoping someone can point me in the right direction.

我正在尝试将HAProxy配置为使用环境变量(来自操作系统)作为acl的一部分声明。
因此,如果在启动或重新加载HAProxy时将环境变量设置为true,则将授予访问权限。如果将环境变量设置为false,那么我只想生成NOSVR错误。

I am trying to configure HAProxy to use an environment variable (from the operating system) as part of an acl statement. So if the environment variable is set to true when HAProxy is started or reloaded then access is granted. If the environment variable is set to false then I would just want the NOSVR error to be generated.

我知道,如果我也输入一条表示$ b $的规则, b use_backend ftp1-srv,除非accessFtp,然后请求通过OK,这似乎表明acl部分无法正常工作。

I know that if I also put in a rule that says use_backend ftp1-srv unless accessFtp then the request goes through OK which seems to indicate that the acl section is is not working.

我在搜索中发现的很少展示如何以这种方式使用环境变量,只是您应该能够使用env(name)从内部状态获取样本

I have found very little in my searches that show how to use environment variables in this way just that you should be able to do a sample fetch from the internal state with env(name)

这是我尝试过的到目前为止:

This is what I have tried so far:

frontend ftp-in
    bind *:2200
    mode tcp
    option tcplog
    log /dev/log local1 debug
    acl accessFtp env(accessFTP) eq true
    use_backend ftp1-srv if accessFtp
backend ftp1-srv
    balance source
    option tcplog
    server ftp1 127.0.0.1:21


推荐答案

acl accessFtp env(accessFTP) eq true

这可能不起作用,因为 eq 是整数等式比较运算符 env()返回一个字符串,而 true 是...好吧,我不确定如何 true 将以字符串的形式进行整数比较,但是无论哪种方式,结果都将不是您期望的。

This probably doesn't work because eq is an integer equality comparison operator, env() returns a string and true is... okay, I'm not sure how true would be typed, in an integer comparison against a string, but either way, the result will not be what you expect.

如果环境变量包含文字字符串 true ,则使用显式字符串比较。

Use an explicit string comparison if the environment variable contains the literal string true.

acl accessFtp env(accessFTP) -m str true

或者,您应该能够如果您只想测试环境变量已设置为任何值,则使用找到一个值匹配测试。如果根本没有设置该值,则应该为false。

Or, you should be able to use the "a value was found" match test if you only want to test that the environment variable has been set to anything. This should be false if the value is not set at all.

acl accessFtp env(accessFTP) -m found

您还可以通过删除命名的acl并将其替换为匿名的acl来整理配置。

You can also tidy up your config by removing the named acl and replacing it with an anonymous one.

use_backend ftp1-srv if accessFtp if { env(accessFTP) -m str true }

这篇关于在haproxy中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆