Read more

load balance unix sockets to UDP destinations

Moritz Kraus
December 02, 2022Software engineer at makandra GmbH

Nginx is capable of forwarding a unix socket to UDP backend servers. This is quite handy for load balance syslog traffic.

Example nginx configuration

load_module /usr/share/nginx/modules/ngx_stream_module.so;

stream {
    upstream syslog_servers {
        server 192.0.2.10:514;
        server 192.0.2.11:514;
        server 192.0.2.12:514;
    }
    server {
        listen unix:/run/nginx/log.sock udp;
        proxy_pass syslog_server;
    }
}

Testing the connection

echo "Hello Syslog!" | socat - /run/nginx/log.sock

Info

There are cases where nginx does not clean up the socket files after shutdown.

Systemd managed runtime dir

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

The RuntimeDirectory configuration ensures the creation and deletion of the directory /run/nginx on startup and shutdown of the process.

# /etc/systemd/system/nginx.service.d/runtime-dir.conf
[Service]
RuntimeDirectory=nginx
Posted by Moritz Kraus to makandra Operations (2022-12-02 12:38)