|
| 1 | +{ |
| 2 | + {$CADDY_GLOBAL_OPTIONS} |
| 3 | + |
| 4 | + frankenphp { |
| 5 | + {$FRANKENPHP_CONFIG} |
| 6 | + } |
| 7 | + |
| 8 | + # https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm |
| 9 | + order php_server before file_server |
| 10 | +} |
| 11 | + |
| 12 | +{$CADDY_EXTRA_CONFIG} |
| 13 | + |
| 14 | +(404) { |
| 15 | + rewrite * /errors/404.php |
| 16 | +} |
| 17 | + |
| 18 | +{$SERVER_NAME} { |
| 19 | + log { |
| 20 | + output file /var/log/caddy.log |
| 21 | + } |
| 22 | + |
| 23 | + root * /var/www/html/pub |
| 24 | + encode zstd br gzip |
| 25 | + |
| 26 | + {$CADDY_SERVER_EXTRA_DIRECTIVES} |
| 27 | + |
| 28 | + # Deny access to sensitive files and directories |
| 29 | + @sensitiveFiles { |
| 30 | + path_regexp sensitiveFiles /(\.user.ini|\.php$|.*\.phtml$|\.htaccess$|\.htpasswd$|\.git|.*\.txt|.*\.md|errors\/.*\.xml|media\/theme_customization\/.*\.xml) |
| 31 | + } |
| 32 | + @sensitiveDirectories { |
| 33 | + path_regexp sensitiveDirectories /(media\/customer\/*|media\/downloadable\/*|media\/import\/*|media\/custom_options\/*|setup\/*) |
| 34 | + } |
| 35 | + |
| 36 | + # Rewrite to 404 for sensitive files and directories |
| 37 | + handle @sensitiveFiles { |
| 38 | + import 404 |
| 39 | + } |
| 40 | + handle @sensitiveDirectories { |
| 41 | + import 404 |
| 42 | + } |
| 43 | + |
| 44 | + # Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics |
| 45 | + header ?Permissions-Policy "browsing-topics=()" |
| 46 | + |
| 47 | + php_server |
| 48 | + |
| 49 | + @staticPath path_regexp reg_static ^/static/(version\d*/)?(.*)$ |
| 50 | + handle @staticPath { |
| 51 | + @static file /static/{re.reg_static.2} |
| 52 | + rewrite @static /static/{re.reg_static.2} |
| 53 | + |
| 54 | + @staticFiles { |
| 55 | + path *.ico *.jpg *.jpeg *.png *.gif *.svg *.svgz *.webp *.avif *.avifs *.js *.css *.eot *.ttf *.otf *.woff *.woff2 *.html *.json *.webmanifest |
| 56 | + } |
| 57 | + handle @staticFiles { |
| 58 | + # Set headers for matched static assets |
| 59 | + header Cache-Control "public, max-age=31536000" |
| 60 | + } |
| 61 | + @noCacheFiles { |
| 62 | + path *.zip *.gz *.gzip *.bz2 *.csv *.xml |
| 63 | + } |
| 64 | + handle @noCacheFiles { |
| 65 | + # Set Cache-Control header to no-store |
| 66 | + header Cache-Control "no-store, no-cache, must-revalidate" |
| 67 | + } |
| 68 | + |
| 69 | + @dynamic not file /static/{re.reg_static.2} |
| 70 | + rewrite @dynamic /static.php?resource={re.reg_static.2} |
| 71 | + header X-Frame-Options "SAMEORIGIN" |
| 72 | + } |
| 73 | + |
| 74 | + handle /media/* { |
| 75 | + @staticFiles { |
| 76 | + path *.ico *.jpg *.jpeg *.png *.gif *.svg *.svgz *.webp *.avif *.avifs *.js *.css *.eot *.ttf *.otf *.woff *.woff2 |
| 77 | + } |
| 78 | + handle @staticFiles { |
| 79 | + # Set Cache-Control header for 1 year caching |
| 80 | + header Cache-Control "public, max-age=31536000" |
| 81 | + } |
| 82 | + @noCacheFiles { |
| 83 | + path *.zip *.gz *.gzip *.bz2 *.csv *.xml |
| 84 | + } |
| 85 | + handle @noCacheFiles { |
| 86 | + # Set Cache-Control header to no-store |
| 87 | + header Cache-Control "no-store, no-cache, must-revalidate" |
| 88 | + } |
| 89 | + |
| 90 | + try_files {path} {path}/ /get.php{query} |
| 91 | + header X-Frame-Options "SAMEORIGIN" |
| 92 | + } |
| 93 | + |
| 94 | + # PHP entry point for main application |
| 95 | + @phpFiles path /index.php /get.php /static.php /errors/report.php /errors/404.php /errors/503.php /health_check.php |
| 96 | + handle @phpFiles { |
| 97 | + try_files {path} {path}/ =404 |
| 98 | + } |
| 99 | + |
| 100 | + handle_errors 404 403 { |
| 101 | + import 404 |
| 102 | + } |
| 103 | +} |
0 commit comments