Skip to content

Caddy configuration

Jan Tojnar edited this page Jun 20, 2026 · 4 revisions

Here is an example of Caddyfile for running selfoss. Not sure this is the most idiomatic config.

You might need to adjust:

  • domain to run selfoss on: example.com
  • path selfoss is installed to: /var/www/selfoss
  • php-fpm socket path: /var/run/php-fpm/php-fpm.sock
example.com {
    root * /var/www/selfoss

    # Ensure these cannot be leaked.
    @private path /config.ini /data/*
    handle @private {
        respond "Access denied" 403 {
            close
        }
    }

    # Images for feeds
    @media path /favicons/* /thumbnails/*
    handle @media {
        rewrite * /data{path}
        # Keep for a month, favicons might be updated.
        header Cache-Control "max-age=2592000"
        file_server
    }

    # Static assets for PWA support
    @pwa_assets path /selfoss-sw-offline.js /selfoss.webmanifest
    handle @pwa_assets {
        rewrite * /public{path}
        # Not doing cache busting.
        header Cache-Control "no-cache"
        file_server
    }

    # Static assets
    @assets file /public{path}
    handle @assets {
        rewrite * /public{path}
        header Cache-Control "public, max-age=31536000, immutable"
        file_server
    }

    # User customization
    @user_assets path /user.js /user.css
    handle @user_assets {
        # We bust cache using query string parameter.
        header Cache-Control "max-age=31536000, immutable"
        file_server
    }

    handle {
        try_files /index.php
        header Cache-Control "no-cache"
        php_fastcgi unix//var/run/php-fpm/php-fpm.sock
    }
}

Clone this wiki locally