在 HAProxy 配置侦听中使用环境变量不起作用
Using environment variable in HAProxy config listen isn't working
这是 haproxy 配置文件的简单 listen
部分:
listen graph_front
bind *:8182
mode tcp
server graph_server graph.server.com:8182
这很好用,但我需要将地址和端口作为环境变量。所以我把它改成这样:
listen graph_front
bind *:8182
mode tcp
server graph_server "$GRAPH_ADDRESS":"$GRAPH_PORT"
haproxy服务器重新启动就好了,但它不再转发到环境变量中的地址。
有什么想法吗?
上面的配置没问题。这就是我开始使用 haproxy 的方式。我必须直接用
启动它
haproxy -f /path/to/config
如果没有提升的权限,这将不起作用。那么,接下来
sudo haproxy -f /path/to/config
当然环境变量不是通过 sudo 传递的。
所以更直接的方法是这样的:
sudo -- sh -c 'export GRAPH_ADDRESS=graph.server.com; export GRAPH_PORT=8182; haproxy -f /etc/haproxy/haproxy.cfg
这是 haproxy 配置文件的简单 listen
部分:
listen graph_front
bind *:8182
mode tcp
server graph_server graph.server.com:8182
这很好用,但我需要将地址和端口作为环境变量。所以我把它改成这样:
listen graph_front
bind *:8182
mode tcp
server graph_server "$GRAPH_ADDRESS":"$GRAPH_PORT"
haproxy服务器重新启动就好了,但它不再转发到环境变量中的地址。
有什么想法吗?
上面的配置没问题。这就是我开始使用 haproxy 的方式。我必须直接用
启动它haproxy -f /path/to/config
如果没有提升的权限,这将不起作用。那么,接下来
sudo haproxy -f /path/to/config
当然环境变量不是通过 sudo 传递的。 所以更直接的方法是这样的:
sudo -- sh -c 'export GRAPH_ADDRESS=graph.server.com; export GRAPH_PORT=8182; haproxy -f /etc/haproxy/haproxy.cfg