Error during parsing: File to import not found: snippetname

1. Caddy version (caddy version):


2. How I run Caddy:


a. System environment:


b. Command:

sudo docker-compose up

c. Service/unit/compose file:

version: "3.8"

container_name: caddy
image: caddy:latest
restart: always
- PUID=1000
- PGID=1000
- no-new-privileges:true
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- ./caddy/caddy_data:/data
- ./caddy/caddy_config:/config
- “80:80”
- “443:443”

paste full file contents here

d. My complete Caddyfile or JSON config:

    # GLOBAL
    # Global options block. Entirely optional, https is on by default
    # Optional email key for lets encrypt
    email email@com
    # Optional staging lets encrypt for testing. Comment out for production.


respond /forbidden "Access denied" 403 {

# deny all access to these folders
@denied_folders {
    path_regexp /(.github|cache|bin|logs|backups|tests|content|core)/.*$
rewrite @denied_folders /forbidden

# deny running scripts inside core system folders
@denied_system_scripts {
    path_regexp /(core|content|test|system|vendor)/.*\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat|yml|js)$
rewrite @denied_system_scripts /forbidden

# deny running scripts inside user folder
@denied_user_folder {
    path_regexp /user/.*\.(txt|md|yaml|php|pl|py|cgi|twig|sh|bat|yml|js)$
rewrite @denied_user_folder /forbidden

# deny access to specific files in the root folder
@denied_root_folder {
    path_regexp /(config.production.json|config.development.json|index.js|package.json|renovate.json|yarn.lock|.editorconfig|.eslintignore|.eslintrc.json|.gitattributes|.gitignore|.gitmodules|.npmignore|Gruntfile.js|LICENSE|MigratorConfig.js|LICENSE.txt|composer.lock|composer.json|nginx.conf|web.config|htaccess.txt|\.htaccess)
rewrite @denied_root_folder /forbidden

# block bad crawlers
@badbots {
        header User-Agent "*watch*,*explorer*,*pock*,*link*,*vacuum*,*anonym*,*mag-net*,*searchbot*,*seek*,*tool*,*robot*,*szukacz*,*snoop*,*power*,*takeout*,*teleport*,*superbot*,*scan*,*track*,*offline*,*nextgen*,*keyword*,*backweb*,*bandit*,*easydl*,*zip*,*email*,*enhancer*,*ftp*,*fetch*,*auto*,*clip*,*copier*,*master*,*reaper*,*sauger*,*quester*,*whack*,*craftbot*,*download*,*extract*,*stripper*,*sucker*,*ninja*,*clshttp*,*spider*,*leacher*,*collector*,*grabber*,*webpictures*,*file*,*intel*,*loader*,*nameprotect*,*mirror*,*magnet*"
rewrite @badbots /forbidden

# Global rewrite
try_files {path} {path}/ /index.*


(mustheaders) {
        header {
                Strict-Transport-Security "max-age=31536000; includesubdomains; preload"
                Content-Security-Policy "default-src https: 'unsafe-inline' 'unsafe-eval'"
                X-Content-Type-Options "nosniff"
                Cache-Control "public, max-age=604800, must-revalidate"
                X-Frame-Options "SAMEORIGIN"
                Referrer-Policy "strict-origin-when-cross-origin"
                X-Xss-Protection "1; mode=block"
                Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'none'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture *; speaker 'none'; sync-xhr 'none'; usb 'none'; vr 'none'"
                Expect-CT "max-age=604800"
(offlinewebsite) {
        header {
                X-Robots-Tag "noindex, nofollow, noarchive, nosnippet, notranslate, noimageindex"

(onlinewebsite) {
        header {
                X-Robots-Tag "noarchive, notranslate"

(proxy) {
        header_up X-Forwarded-Proto {scheme}
        header_up X-Forwarded-For {remote}
        header_up X-Real-IP {remote}
        header_down X-Powered-By "the Holy Spirit"
        header_down Server "CERN httpd"
(compression) {
        encode zstd gzip


www.{$GHOST} {
        redir * https://{}.{}{path} permanent


{$GHOST} {
        import mustheaders
        import offlinewebsite
        reverse_proxy {
                import proxy

        log {
        output file /var/log/caddy/caddy.log
        format single_field common_log

3. The problem I’m having:

caddy thinks the “mustheaders” is a file not the snippet.

4. Error messages and/or full log output:

{“level”:“info”,“ts”:1612532800.0255752,“msg”:“using provided configuration”,“config_file”:"/etc/caddy/Caddyfile",“config_adapter”:“caddyfile”}
caddy | run: adapting config using caddyfile: /etc/caddy/Caddyfile:97 - Error during parsing: File to import not found: mustheaders

Your Caddyfile isn’t structured correctly.

Globals go first, then you should define your snippets, then your sites.

You cannot have directives outside of a site block, they must go inside a site block.

You also cannot have matcher definitions outside of site blocks, they must go inside one. You can use snippets to reuse them for multiple sites.

Should I grab the “# Security Config” section into snippet and then import it to the site alongside import offlinewebsite? Tried it. Still error exists.
problem solved as try_files was in the wrong place as well.

This topic was automatically closed after 30 days. New replies are no longer allowed.