OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • The Wayland Display 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
        • Post-Quantum Cryptography on OpenBSD
    • 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
          • Run FreeBSD on OpenBSD with vmd
          • 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
          • Run Sway 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 Handbook Style Guide
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
          • Web Server History on OpenBSD
        • Web Server Comparison
        • Installation
        • Basic Configuration
        • Starting nginx
        • TLS Configuration
          • Verify the TLS Group
        • FastCGI Support (PHP, etc.)
        • Reverse Proxy Example
        • Logging and Diagnostics
        • Security Practices

        nginx Web Server

        Synopsis #

        nginx is an HTTP server and reverse proxy. It supports static content, TLS, FastCGI and SCGI backends, load balancing, and basic authentication.

        nginx is not included in the OpenBSD base system, but is available via packages.

        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, dependencies, and OpenBSD README instructions are available in the release package and current package entries. The package branch must match the installed OpenBSD system.

        Install nginx from packages:

        doas pkg_add nginx
        

        This installs:

        • /etc/nginx/nginx.conf – main configuration file
        • /usr/local/sbin/nginx – daemon binary
        • rc.d service script for rcctl(8)

        Basic Configuration #

        The default configuration file is installed at /etc/nginx/nginx.conf.

        Minimal example for static file hosting:

        worker_processes  1;
        
        events {
            worker_connections  1024;
        }
        
        http {
            include       mime.types;
            default_type  application/octet-stream;
        
            sendfile        on;
            keepalive_timeout  65;
        
            server {
                listen       80;
                server_name  localhost;
        
                root /htdocs;
                index index.html;
        
                location / {
                    try_files $uri $uri/ =404;
                }
            }
        }
        

        nginx workers run in a chroot at /var/www by default. Their /htdocs is /var/www/htdocs on the host. Create that directory and a test file:

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

        Starting nginx #

        Enable and start the service:

        doas rcctl enable nginx
        doas rcctl start nginx
        

        To test or reload configuration:

        doas nginx -t
        doas nginx -s reload
        

        The process runs as the www user.

        TLS Configuration #

        To enable HTTPS, obtain a certificate (e.g., via acme-client) and adjust the configuration:

        server {
            listen 443 ssl;
            server_name example.org;
        
            ssl_certificate     /etc/ssl/example.org.fullchain.pem;
            ssl_certificate_key /etc/ssl/private/example.org.key;
        
            root /htdocs;
            index index.html;
        
            location / {
                try_files $uri $uri/ =404;
            }
        }
        

        Do not forget to open port 443 in pf.conf:

        pass in on $int_if proto tcp from any to (self) port 443
        

        Verify the TLS Group #

        Identify the installed binary and its TLS library with nginx and ldd(1). A second TLS command-line tool on the host does not change the library used by the running service.

        $ /usr/local/sbin/nginx -V 2>&1
        $ ldd /usr/local/sbin/nginx
        

        Packaged nginx 1.30.6 on OpenBSD 8.0 reported LibreSSL 4.4.0 and loaded libssl from /usr/lib. An unmodified group policy negotiated X25519MLKEM768 with a capable client. nginx provides ssl_ecdh_curve auto as its default since 1.11.0. The TLSv1.3 parameter appeared in nginx 1.13.0 and entered the default protocol list in 1.23.4. Review an explicit classical-only curve list before adding any directive. OpenSSL builds with 3.5 or later can also negotiate this group. See the nginx TLS module.

        Use an OpenSSL 3.5 diagnostic client. The OpenBSD openssl package used here supplies eopenssl35 separately from base LibreSSL.

        $ eopenssl35 s_client -connect www.example.org:443 -servername www.example.org \
            -verify_hostname www.example.org -verify_return_error -tls1_3 -brief </dev/null
        

        Use a fresh TLS 1.3 connection to the name clients use. Start with the default group offer. With OpenSSL 3.5, look for Verification: OK and Negotiated TLS1.3 group: X25519MLKEM768. A peer temporary key of X25519 alone indicates classical exchange. Read the separate Signature type: field for the TLS CertificateVerify signature. For example, rsa_pss_rsae_sha256 identifies RSA-PSS and mldsa65 identifies ML-DSA-65. The issuer signature on the certificate is another field. The cipher suite identifies the record cipher and hash. An RSA or ECDSA certificate can authenticate either exchange.

        Repeat with -groups X25519MLKEM768 to test whether that endpoint can accept the hybrid group. A forced success establishes capability for that client. Repeat with representative browsers and older clients to check normal selection and fallback. If a CDN terminates public TLS, the public result describes the CDN. Test the authorized origin separately with its correct address, SNI name and trust chain. See post-quantum cryptography on OpenBSD, the OpenSSL client manual and TLS 1.3 group negotiation.

        FastCGI Support (PHP, etc.) #

        To serve dynamic content (e.g., via php-fpm):

        1. Install PHP 8.3, the release default; the main package includes PHP-FPM:
        doas pkg_add php%8.3
        doas php-fpm-8.3 -t
        doas rcctl enable php83_fpm
        doas rcctl start php83_fpm
        
        1. With PHP-FPM chrooted to /var/www, put the site files in /var/www/htdocs on the host. Its socket must be /var/www/run/php-fpm.sock and accessible to www. Inside the nginx chroot, the socket is /run/php-fpm.sock. Add this location to the nginx server:
        location ~ \.php$ {
            root           /htdocs;
            fastcgi_pass   unix:/run/php-fpm.sock;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME /htdocs$fastcgi_script_name;
        }
        

        Ensure PHP files exist in the document root:

        doas sh <<'ROOT'
        mkdir -p /var/www/htdocs
        echo "<?php echo 'PHP works'; ?>" > /var/www/htdocs/index.php
        ROOT
        

        Reverse Proxy Example #

        nginx can proxy requests to a backend service, such as a Python or Node.js application:

        server {
            listen 80;
        
            location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
            }
        }
        

        This setup is commonly used for application frontends, TLS termination, or caching.

        Logging and Diagnostics #

        Access and error logs are defined in the http block:

        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
        

        Create /var/log/nginx before applying that custom log configuration. Validate with nginx -t and confirm both files are created.

        To follow logs:

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

        Use nginx -t to verify syntax, and rcctl restart nginx after changes.

        Security Practices #

        • Run nginx as www (default).
        • Ensure host-side files in /var/www/htdocs are readable by www and not world-writable.
        • Use try_files to select existing files; it is not a general path-traversal defense. Review roots, aliases, and application path handling.
        • Do not expose nginx to the Internet without enabling TLS.
        • Validate all reverse proxy headers if used.

        Example pf.conf rules:

        block in proto tcp from any to (self) port { 80 443 }
        pass in on $int_if proto tcp from 192.0.2.0/24 to (self) port { 80 443 }
        
        Report a bug
        • Synopsis
          • Web Server History on OpenBSD
        • Web Server Comparison
        • Installation
        • Basic Configuration
        • Starting nginx
        • TLS Configuration
          • Verify the TLS Group
        • FastCGI Support (PHP, etc.)
        • Reverse Proxy Example
        • Logging and Diagnostics
        • Security Practices