OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • 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
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
          • Web Server History on OpenBSD
        • Web Server Comparison
        • Installation
        • Configuration
        • Starting Apache
        • TLS Support
        • Access Logs
        • Module Management
        • Security Notes

        Apache HTTP Server

        Synopsis #

        The Apache HTTP Server supports virtual hosts, authentication, TLS, CGI, PHP, and dynamically loaded modules.

        Apache is not included in the OpenBSD base system. It is available as a package under the name www/apache-httpd.

        Web Server History on OpenBSD #

        OpenBSD removed the old Apache server from base in 5.6, introduced the native httpd in 5.6, and removed nginx from base in 5.7. Apache and nginx remain available as packages. See the 5.6 release notes and 5.7 release notes .

        Web Server Comparison #

        The Web overview compares httpd, nginx, and Apache and explains the separate role of relayd.

        Installation #

        Package versions and dependencies are available in the release package and current package entries. The package branch must match the installed OpenBSD system.

        Apache is installed via the package system:

        doas pkg_add apache-httpd
        

        This provides the Apache 2.4 binary, modules, configuration templates, and startup script.

        Configuration #

        Apache’s primary configuration file is:

        /etc/apache2/httpd2.conf
        

        The directory /etc/apache2/ also includes subdirectories for optional configurations:

        • extra/ — supplementary virtual host and module settings
        • original/ — saved reference defaults

        To begin, create a simple virtual host configuration:

        ServerRoot "/var/www"
        Listen 80
        
        LoadModule mpm_prefork_module /usr/local/lib/apache2/mod_mpm_prefork.so
        LoadModule dir_module /usr/local/lib/apache2/mod_dir.so
        LoadModule mime_module /usr/local/lib/apache2/mod_mime.so
        TypesConfig /etc/apache2/mime.types
        LoadModule log_config_module /usr/local/lib/apache2/mod_log_config.so
        LoadModule alias_module /usr/local/lib/apache2/mod_alias.so
        LoadModule authz_core_module /usr/local/lib/apache2/mod_authz_core.so
        LoadModule unixd_module /usr/local/lib/apache2/mod_unixd.so
        LoadModule rewrite_module /usr/local/lib/apache2/mod_rewrite.so
        
        User www
        Group www
        
        DocumentRoot "/htdocs"
        <Directory "/htdocs">
            Require all granted
            Options Indexes FollowSymLinks
            AllowOverride None
        </Directory>
        
        ErrorLog "/var/log/apache2-error.log"
        LogFormat "%h %l %u %t \"%r\" %>s %b" common
        CustomLog "/var/log/apache2-access.log" common
        

        Keep ServerRoot at /var/www, the package default. The default PID-file path depends on this directory. Use DocumentRoot to set the directory for site files.

        Create the document root and test file:

        doas sh <<'ROOT'
        mkdir -p /htdocs
        echo 'OK' > /htdocs/index.html
        chown -R www:www /htdocs
        ROOT
        

        Starting Apache #

        The package supplies the apache2 service and the httpd2 binary. Validate and start it with:

        doas /usr/local/sbin/httpd2 -t
        doas rcctl enable apache2
        doas rcctl start apache2
        

        Ensure the selected ports are not already used by base httpd, nginx, or relayd. Preserve package module defaults unless replacing them deliberately.

        TLS Support #

        Apache supports HTTPS via mod_ssl.

        Add the following to /etc/apache2/httpd2.conf:

        LoadModule ssl_module /usr/local/lib/apache2/mod_ssl.so
        
        Listen 443
        <VirtualHost _default_:443>
            DocumentRoot "/htdocs"
            SSLEngine on
            SSLCertificateFile "/etc/ssl/example.crt"
            SSLCertificateKeyFile "/etc/ssl/private/example.key"
        </VirtualHost>
        

        Ensure the certificate and key exist:

        doas ls -l /etc/ssl/example.crt /etc/ssl/private/example.key
        

        You may use Let’s Encrypt and acme-client(1) to obtain valid certificates.

        Restart Apache after enabling TLS:

        doas /usr/local/sbin/httpd2 -t && doas rcctl restart apache2
        

        Access Logs #

        Apache logs access and error information by default:

        • /var/log/apache2-access.log
        • /var/log/apache2-error.log

        To view:

        doas tail -f /var/log/apache2-access.log
        

        Module Management #

        Apache supports many modules. Common examples include:

        • mod_rewrite — URL rewriting
        • mod_alias — aliasing paths
        • mod_cgi — running shell scripts or compiled CGI
        • mod_php — dynamic PHP integration
        • mod_proxy — reverse proxy capabilities

        Modules must be loaded via LoadModule in httpd.conf. Paths refer to .so files under /usr/local/lib/apache2.

        Security Notes #

        Apache runs as the unprivileged www user. Ensure content files are owned appropriately and do not grant write access to system users.

        Example:

        doas chown -R www:www /htdocs
        doas chmod -R o-rwx /htdocs/private
        

        Avoid enabling .htaccess (AllowOverride) unless explicitly needed.

        Use pf.conf to restrict access to port 80/443 as needed:

        pass in on $int_if proto tcp from any to (self) port {80 443}
        
        Report a bug
        • Synopsis
          • Web Server History on OpenBSD
        • Web Server Comparison
        • Installation
        • Configuration
        • Starting Apache
        • TLS Support
        • Access Logs
        • Module Management
        • Security Notes