# Directory for haproxy config files

**URL:** <https://discourse.haproxy.org/t/directory-for-haproxy-config-files/6967>\
**Category:** Help!\
**Created:** [October 8, 2021, 4:09pm UTC](https://discourse.haproxy.org/t/directory-for-haproxy-config-files/6967 "2021-10-08T16:09:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toni](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Toni](https://discourse.haproxy.org/u/Toni)\
**Post date:** [October 8, 2021, 4:09pm UTC](https://discourse.haproxy.org/t/directory-for-haproxy-config-files/6967/1 "2021-10-08T16:09:54Z")

</div>

Hi  
Due to complexity of my `haproxy.cfg` file, I would like to use one of more directories, from which haproxy will read all `*.cfg` files.

In my `/etc/haproxy/haproxy.cfg`, I would like to add a variable with the path (or multiple paths) of the config directory (e.g. `/etc/haproxy/haproxy.d`) - like many other servers do (e.g. Apache, NGINX, named, etc.)

I wasn’t able to find such a setting.  
How can this be done?

P.S. I managed to find a solution, which works, but is too static and clunky - create a directory by hand, and modify haproxy’s systemd unit file to include that directory. I’m looking for a more dynamic, elegant solution.

```auto
$ cat /etc/systemd/system/multi-user.target.wants/haproxy.service | egrep -v '^#|^ *$'
[Unit]
Description=HAProxy Load Balancer
Documentation=man:haproxy(1)
After=syslog.target network.target
[Service]
EnvironmentFile=-/etc/sysconfig/haproxy
Environment="CONFIG=/etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy.d" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify
[Install]
WantedBy=multi-user.target

```

---

<div class="post-metadata">

**Author:** ![Toni](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Toni](https://discourse.haproxy.org/u/Toni)\
**Post date:** [October 18, 2021, 12:58pm UTC](https://discourse.haproxy.org/t/directory-for-haproxy-config-files/6967/2 "2021-10-18T12:58:35Z")

</div>

It should be noted, that with the above configuration, it is easy to misuse the haproxy configuration check:

```auto
haproxy -c -f /etc/haproxy/haproxy.cfg

```

…will only check the haproxy config in this particular file.  
If there is an error in one of the config files under `haproxy.d/*.cfg`, the config check will report the haproxy config as correct, but haproxy may fail to restart.

Of course, the correct way to use haproxy config check in such a case would be:

```auto
haproxy -c -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy.d/

```

As mentioned earlier, using the systemd unit file to include an additional directory for haproxy config files is clunky and prone to errors.

Is there a more elegant way to do it?

For example, in NGINX, it is possible to include further directories using the `include` statement in the main config file.

```auto
include /etc/nginx/conf.d/*.conf;

```

That’s the correct way of doing it, and I am looking for a similar solution in haproxy.
