Hey there!
What I’m up to:
I’m attempting to tweak the Caddyfile used with FrankenPHP + Laravel Octane. This is what’s being used:
Is there a way for me to get the final output from the running server?
{
{$CADDY_GLOBAL_OPTIONS}
admin localhost:{$CADDY_SERVER_ADMIN_PORT}
frankenphp {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
}
}
{$CADDY_SERVER_SERVER_NAME} {
log {
level {$CADDY_SERVER_LOG_LEVEL}
# Redact the authorization query parameter that can be set by Mercure...
format filter {
wrap {$CADDY_SERVER_LOGGER}
fields {
uri query {
replace authorization REDACTED
}
}
}
}
route {
root * "{$APP_PUBLIC_PATH}"
encode zstd br gzip
# Mercure configuration is injected here...
{$CADDY_SERVER_EXTRA_DIRECTIVES}
php_server {
index frankenphp-worker.php
# Required for the public/storage/ directory...
resolve_root_symlink
}
}
}
The Goals
What I’d like to do is add some protections/cache headers for static assets:
- Returning 404 or 401 for dot files and files of specific extensions
- Adding cache headers for static files ending in specific extensions
What I’ve Tried
I’m still working my way around the Caddyfile
and would love any pointers - here’s what I’ve tried (in diff
syntax):
{
{$CADDY_GLOBAL_OPTIONS}
admin localhost:{$CADDY_SERVER_ADMIN_PORT}
frankenphp {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
}
}
{$CADDY_SERVER_SERVER_NAME} {
log {
level {$CADDY_SERVER_LOG_LEVEL}
# Redact the authorization query parameter that can be set by Mercure...
format filter {
wrap {$CADDY_SERVER_LOGGER}
fields {
uri query {
replace authorization REDACTED
}
}
}
}
route {
root * "{$APP_PUBLIC_PATH}"
encode zstd br gzip
# Mercure configuration is injected here...
{$CADDY_SERVER_EXTRA_DIRECTIVES}
php_server {
index frankenphp-worker.php
# Required for the public/storage/ directory...
resolve_root_symlink
}
+ file_server {
+ hide *.bak *.conf *.dist *.fla *.ini *.inc *.inci *.log *.orig *.psd *.sh *.sql *.swo *.swp *.swop */.*
+ }
}
}
However, after restarting Octane, I can still get “protected” files:
Starting a server:
php -d variables_order=EGPCS artisan octane:start \
--server=frankenphp --host=0.0.0.0 --admin-port=2019 \
--port=8080 --caddyfile=./Caddyfile
And sending requests:
curl -i http://0.0.0.0:8080/.env
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 4
Etag: "sdya1l4"
Last-Modified: Thu, 23 May 2024 18:00:57 GMT
Server: Caddy
Date: Thu, 23 May 2024 18:11:05 GMT
foo
---
curl -i http://0.0.0.0:8080/backup.bak
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 9
Etag: "sdyai99"
Last-Modified: Thu, 23 May 2024 18:10:57 GMT
Server: Caddy
Date: Thu, 23 May 2024 18:11:10 GMT
backups!
3. Caddy version:
./frankenphp --version
# FrankenPHP 1.1.5 PHP Caddy v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=
4. How I installed and ran Caddy:
# Laravel setup w/ Octane
composer create-project laravel/laravel frankentest
cd frankentest
composer require laravel/octane
php artisan octane:install --server=frankenphp
# Copy the Caddyfile stub so we can play with it
cp vendor/laravel/octane/src/Commands/stubs/Caddyfile ./Caddyfile
# Start Frankenphp with the local Caddyfile
php -d variables_order=EGPCS artisan octane:start \
--server=frankenphp --host=0.0.0.0 --admin-port=2019 \
--port=8080 --caddyfile=./Caddyfile
a. System environment:
MacOS, M3 (ARM) - This is not in Docker but occurs within Docker as well