OpenBSD Handbook

    • Part I. Install & Configure
      • Introduction
      • Installing OpenBSD
      • The X Window System
      • Networking
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • Graphical Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Security
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • TFTP
        • Mail
          • Dovecot
          • smtpd
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Named
          • Unbound
          • NSD
        • Networking
          • OpenBGPD
          • rtadvd
          • DHCP
          • slaacd
        • Web
          • Apache
          • nginx
          • httpd
          • relayd
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • sshd
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ
        • Time
          • NTP
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • Howto
        • Install Z shell (zsh)
        • Set Up WordPress
        • Build a Simple Router and Firewall
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • Package Search
      relayd
      • Synopsis
      • Common Use Cases
      • Basic TLS Terminating Reverse Proxy
        • Example: TLS frontend to local httpd(8)
      • Backend Pool with Load Balancing
      • Redirecting HTTP to HTTPS
      • Using relayd with FastCGI
      • Logging and Monitoring
      • Security Considerations
      • Example pf.conf Rule
      • Service Management

      relayd

      Synopsis #

      relayd(8) is OpenBSD’s native application-layer proxy and filtering daemon. It supports:

      • Reverse proxying (HTTP/HTTPS)
      • TLS termination with optional re-encryption
      • HTTP/HTTPS load balancing with active health checks
      • Layer 7 filtering, header rewriting, and redirection

      relayd is included in the OpenBSD base system and integrates tightly with pf(4) and httpd(8). It is configured via /etc/relayd.conf.

      Use relayd when you need to expose HTTP or HTTPS services securely, filter traffic at the application layer, or distribute requests across multiple backends.

      Common Use Cases #

      • Terminate TLS and forward HTTP to a local backend
      • Filter and forward incoming HTTPS to multiple application servers
      • Load-balance FastCGI traffic to PHP-FPM sockets
      • Implement virtual hosting with separate domains and TLS keys

      Basic TLS Terminating Reverse Proxy #

      The most common relayd use case is to accept TLS connections and forward them unencrypted to a backend.

      Example: TLS frontend to local httpd(8) #

      relay "tlsproxy" {
          listen on egress port 443 tls
              tls certificate "/etc/ssl/example.org.fullchain.pem"
              tls key "/etc/ssl/private/example.org.key"
      
          forward to 127.0.0.1 port 8080
      }
      

      On the backend, httpd(8) should listen on localhost port 8080:

      server "example.org" {
          listen on 127.0.0.1 port 8080
          root "/htdocs/example"
      }
      

      Start both services:

      # rcctl enable relayd httpd
      # rcctl start relayd httpd
      

      Allow traffic on port 443 in pf.conf:

      pass in on egress proto tcp to port 443
      

      Backend Pool with Load Balancing #

      relayd can distribute traffic across multiple backend hosts using a table:

      table <webservers> { 192.0.2.10, 192.0.2.11, 192.0.2.12 }
      
      relay "cluster" {
          listen on egress port 80
          forward to <webservers> port 80
      }
      

      Backends are monitored by default via TCP connect checks.

      To use HTTP health checks:

      table <webservers> {
          192.0.2.10 check http "/" code 200
          192.0.2.11 check http "/status" code 200
      }
      

      View real-time status:

      # relayctl show hosts
      

      Redirecting HTTP to HTTPS #

      relayd supports inline HTTP redirection:

      relay "http-redirect" {
          listen on egress port 80
          protocol "redirect"
      }
      
      protocol "redirect" {
          match request path "*" forward to "https://example.org"
      }
      

      This listens on port 80 and redirects all HTTP traffic to HTTPS.

      Using relayd with FastCGI #

      To serve FastCGI backends (e.g., PHP-FPM) through httpd(8), relayd can forward requests to Unix sockets:

      table <phpfpm> { socket "/run/php-fpm.sock" }
      
      relay "fcgi" {
          listen on 127.0.0.1 port 9000
          forward to <phpfpm>
      }
      

      In httpd.conf:

      server "site" {
          listen on egress port 80
          root "/htdocs/site"
          location "*.php" {
              fastcgi socket "127.0.0.1" port 9000
          }
      }
      

      Note: In most cases, httpd(8) can connect directly to the socket without relayd.

      Logging and Monitoring #

      Enable logging in /etc/relayd.conf:

      log updates
      log state
      

      Tail logs via syslog:

      # tail -f /var/log/daemon
      

      Query runtime state:

      # relayctl show sessions
      # relayctl show hosts
      # relayctl statistics
      

      Reload configuration without restart:

      # rcctl reload relayd
      

      Security Considerations #

      • relayd runs as _relayd and is not chrooted
      • TLS private keys must be readable by _relayd, typically 640 owned by root:_relayd
      • Ensure only intended IPs can access TLS ports
      • Combine with pf(4) for full traffic filtering

      Example pf.conf Rule #

      block in all
      pass in on egress proto tcp from any to (self) port 443
      pass in on egress proto tcp from any to (self) port 80
      

      Limit access to internal-only relays by using loopback or RFC1918 address bindings.

      Service Management #

      Enable at boot and manage via rcctl:

      # rcctl enable relayd
      # rcctl start relayd
      # rcctl check relayd
      

      Check for syntax errors:

      # relayd -n -f /etc/relayd.conf
      

      Reload configuration:

      # rcctl reload relayd
      
      Report a bug
      • Synopsis
      • Common Use Cases
      • Basic TLS Terminating Reverse Proxy
        • Example: TLS frontend to local httpd(8)
      • Backend Pool with Load Balancing
      • Redirecting HTTP to HTTPS
      • Using relayd with FastCGI
      • Logging and Monitoring
      • Security Considerations
      • Example pf.conf Rule
      • Service Management