# How to update Caddyfile using tutor plugin

**URL:** <https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944>\
**Category:** Site Operators\
**Tags:** how-to, tutor\
**Created:** [December 15, 2022, 12:09pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944 "2022-12-15T12:09:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![partha](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/partha/32/4644_2.png) [@partha](https://discuss.openedx.org/u/partha)\
**Post date:** [December 15, 2022, 12:09pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/1 "2022-12-15T12:09:47Z")

</div>

I am trying to increase the upload content size. Default size is 100MB.  
I am trying to change it to 500MB.  
I am able to change in the openedx-cms-production-settings using tutor plugin.  
I have to update the same in Caddyfile located at the the location **“$(tutor config printroot)/env/apps/caddy/Caddyfile”** for the following entry **[studio.lms-dev.techsophy.com](http://studio.lms-dev.techsophy.com){$default\_site\_port}**  
I have directly edited the file and changed the value of max\_size to 500MB and it is working.

How to I apply this change using tutor plugin? Need some hint

---

<div class="post-metadata">

**Author:** ![arbrandes](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/arbrandes/32/158_2.png) [@arbrandes](https://discuss.openedx.org/u/arbrandes)\
**Post date:** [December 15, 2022, 12:22pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/2 "2022-12-15T12:22:23Z")

</div>

Hello @partha, welcome!

There are several patch hooks in the Caddyfile you can take advantage in a plugin. For instance, [caddyfile-cms](https://github.com/overhangio/tutor/blob/master/tutor/templates/apps/caddy/Caddyfile#L64). I’m no Caddy expert, but I believe you could create a plugin like so, and it would get you what you need:

```auto
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
    (
        "caddyfile-cms",
        """
    request_body {
        max_size 500MB
    }
"""
    )
)

```

Let us know if it works!

---

<div class="post-metadata">

**Author:** ![Anh\_Vu\_Nguy\_n](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/anh_vu_nguy_n/32/1740_2.png) [@Anh\_Vu\_Nguy\_n](https://discuss.openedx.org/u/Anh_Vu_Nguy_n)\
**Post date:** [December 15, 2022, 12:36pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/3 "2022-12-15T12:36:53Z")

</div>

> [@partha](#):
>
> 100MB

I don’t think using tutor plugin would work because the request\_body.max\_size is appended at the bottom of the settings and it will be ignored by the default value.

> <https://github.com/overhangio/tutor/blob/master/tutor/templates/apps/caddy/Caddyfile>

One workaround way that I can think about is to modify the tutor Caddyfile template at  
/home/ubuntu/.local/lib/python3.8/site-packages/tutor/templates/apps/caddy/Caddyfile  
but you have to manually set this value everytime you upgrade tutor.

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [December 15, 2022, 2:09pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/4 "2022-12-15T14:09:18Z")

</div>

@partha can you please check whether implementing the “caddyfile-cms” and “caddyfile-lms” patches works for you? If not, would they work if the patch was located before the `import proxy "lms:8000"/import proxy "cms:8000"` statements?

---

<div class="post-metadata">

**Author:** ![partha](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/partha/32/4644_2.png) [@partha](https://discuss.openedx.org/u/partha)\
**Post date:** [December 16, 2022, 5:35am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/5 "2022-12-16T05:35:39Z")

</div>

The plugin did not work though the Caddy file was updated as bellow

```auto
 request_body {
        max_size 250MB
    }

    import proxy "cms:8000"

        request_body {
            max_size 500MB
        }

```

---

<div class="post-metadata">

**Author:** ![partha](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/partha/32/4644_2.png) [@partha](https://discuss.openedx.org/u/partha)\
**Post date:** [December 16, 2022, 5:55am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/6 "2022-12-16T05:55:18Z")

</div>

Even after modifying the Caddyfiles as suggested by @regis it did not work. Following are the changes I made.  
I have manually edited the Caddyfile at location  
**“$(tutor config printroot)/env/apps/caddy/Caddyfile”**  
moved the request\_body section before import as shown bellow

```auto
request_body {
            max_size 500MB
        }
    import proxy "cms:8000"

```

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [December 16, 2022, 1:42pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/7 "2022-12-16T13:42:12Z")

</div>

Thank you @partha. And you did restart caddy every time to take your changes into account, right? (`tutor local restart caddy`)

---

<div class="post-metadata">

**Author:** ![partha](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/partha/32/4644_2.png) [@partha](https://discuss.openedx.org/u/partha)\
**Post date:** [December 16, 2022, 3:39pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/8 "2022-12-16T15:39:30Z")

</div>

Yes I did restart the services after the changes.

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [January 30, 2023, 10:32am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/9 "2023-01-30T10:32:24Z")

</div>

Sorry it took me so long to get back to you @partha. I propose that we move the “caddyfile-cms” and “caddyfile-lms” patches just before the `import proxy` line. I believe this should resolve your issue, as you would be able to create a patch that overrides the max\_size. Right?

EDIT: see this pull request [feat: overridable lms/cms max upload size by regisb · Pull Request #792 · overhangio/tutor · GitHub](https://github.com/overhangio/tutor/pull/792) As explained in the PR description, once it is merged you should be able to modify the upload max size by adding the following to the “caddyfile-cms” patch:

```auto
handle_path /import/* {
    request_body {
        max_size 500MB
    }
}

```

---

<div class="post-metadata">

**Author:** ![sambapete](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/sambapete/32/4100_2.png) [@sambapete](https://discuss.openedx.org/u/sambapete)\
**Post date:** [January 30, 2023, 4:25pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/10 "2023-01-30T16:25:59Z")

</div>

YES! @regis that would solve the issue we currently have and that I mentioned way back in [Caddy issues with ID Verification](https://discuss.openedx.org/t/caddy-issues-with-id-verification/8276)

Thank you!

---

<div class="post-metadata">

**Author:** ![joel.edwards](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/joel.edwards/32/3193_2.png) [@joel.edwards](https://discuss.openedx.org/u/joel.edwards)\
**Post date:** [October 12, 2023, 11:48am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/11 "2023-10-12T11:48:38Z")

</div>

@partha did you ever find a lasting solution for max\_size as a plugin?

@regis, I’m by no means an expert in the plugins system but having had a look at the template and the list of available patches, it appears to me that the max\_size value is hard coded into the template and so cannot be defined by a patch as that will simply add a value to CaddyFile instead of overwriting the defaults, this might break syntax or at the very least introduce duplication of directives for Caddy. (thinking back to running apache/nginx sites in the past these kind of things can cause issues but it’s been a long time since I did, I’m anticipating that Caddy might behave similarly)

Additionally, insofar as I can tell, the following patch (unless I misunderstood it’s function) has no effect in relation to Caddy’s max\_size directive (whether or not that’s how it’s supposed to be I’m unsure)  
openedx-cms-production-settings: |  
MAX\_ASSET\_UPLOAD\_FILE\_SIZE\_IN\_MB

I think I might have some ideas how to work around this but not sure how/if it would interact with anything in unexpected ways. **Note I have not tested any of this, it’s just theory I came up with in my head, please don’t implement unless I’m not a complete idiot (see footnote at bottom)**

Possible option:  
Add new patch directives for each max\_size value in the template, example:

```auto
{{ LMS_HOST }}{$default_site_port}, {{ PREVIEW_LMS_HOST }}{$default_site_port} {
    @favicon_matcher {
        path_regexp ^/favicon.ico$
    }
    rewrite @favicon_matcher /theming/asset/images/favicon.ico

    # Limit profile image upload size
    handle_path /api/profile_images/*/*/upload {
        request_body {
            {{ patch("caddyfile-lms-profile_images_max_size")|indent(4) }}
        }
    }

    import proxy "lms:8000"

    {{ patch("caddyfile-lms")|indent(4) }}

    handle_path /* {
        request_body {
            {{ patch("caddyfile-lms-max_size")|indent(4) }}
        }
    }
}

{{ CMS_HOST }}{$default_site_port} {
    @favicon_matcher {
        path_regexp ^/favicon.ico$
    }
    rewrite @favicon_matcher /theming/asset/images/favicon.ico

    import proxy "cms:8000"

    {{ patch("caddyfile-cms")|indent(4) }}

    handle_path /* {
        request_body {
            {{ patch("caddyfile-cms-max_size")|indent(4) }}
        }
    }
}

```

Though if my understanding is right this will break the build for everyone who is NOT using a patch as it won’t have default values to assign.  
Perhaps default values can be kept in the file with a condition _(similar to the Global config at the top like {% if not ENABLE\_WEB\_PROXY %})_ where we can have an option in config.yml to choose  
eg: CADDYFILE\_USEDEFAULT\_MAX\_SIZE: [true|false] (where false implies to use patch and true specifies use built-in defaults.  
Maybe something like this?:

```auto
{{ CMS_HOST }}{$default_site_port} {
    @favicon_matcher {
        path_regexp ^/favicon.ico$
    }
    rewrite @favicon_matcher /theming/asset/images/favicon.ico

    import proxy "cms:8000"

    {{ patch("caddyfile-cms")|indent(4) }}

    handle_path /* {
        request_body {
            {% if not CADDYFILE_USEDEFAULT_MAX_SIZE %}
            max_size 250MB
    {% else %}
    {{ patch("caddyfile-cms-max_size")|indent(4) }}
    {% endif %}

            
        }
    }
}

```

**Though please DO assume that I might be an idiot who doesn’t know what they’re talking about, my level of expertise with caddy/tutor is not great, this is all guesswork. The patch/variable names I supplied are for illustrative purposes and not intended to be a final suggestion**

---

<div class="post-metadata">

**Author:** ![sbernesto](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/sbernesto/32/90_2.png) [@sbernesto](https://discuss.openedx.org/u/sbernesto)\
**Post date:** [January 4, 2024, 4:49pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/12 "2024-01-04T16:49:32Z")

</div>

Hello,

I made this plugin

```auto
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
    (
        "caddyfile-cms",
        """
handle_path /import/* {
    request_body {
      max_size 500MB
    }
}
"""
    )
)

```

but when I apply it it always returns a 404 error in the caddy log

```auto
tutor_local-caddy-1 | {"level":"error","ts":1704386774.3679094,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_ip":"192.168.88.62","remote_port":"4705","proto":"HTTP/1.1","method":"GET","host":"studio.dev.lan","uri":"/import/course-v1:edX+DemoX+Demo_Course"},"user_id":"","duration":0.087692554,"size":2608,"status":404}

```

How should I correct this error in the plugin?

---

<div class="post-metadata">

**Author:** ![vivek](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/vivek/32/6825_2.png) [@vivek](https://discuss.openedx.org/u/vivek)\
**Post date:** [March 13, 2024, 5:44am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/13 "2024-03-13T05:44:06Z")

</div>

@regis or @partha , i just go through disscussion but still when i save caddy file and these are changes which reflects due to plugin

```auto
studio.local.edly.io{$default_site_port} {
    @favicon_matcher {
        path_regexp ^/favicon.ico$
    }
    rewrite @favicon_matcher /theming/asset/images/favicon.ico

    import proxy "cms:8000"

    handle_path /import/* {
	request_body {
	   max_size 500MB
	}
   }

    handle_path /* {
        request_body {
            max_size 250MB
        }
    }
}

```

here is my plugin which i made

```auto
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
    (
        "caddyfile-cms",
        """
    handle_path /import/* {
	request_body {
	   max_size 500MB
	}
   }
"""
    )
)

```

Could you please provide me a solution , as your disscussion seems to have high understanding of tutor and i joined recently , so i done what i understand through your disscusion

---

<div class="post-metadata">

**Author:** ![darsh\_modi97](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@darsh\_modi97](https://discuss.openedx.org/u/darsh_modi97)\
**Post date:** [May 6, 2025, 9:57am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/14 "2025-05-06T09:57:20Z")

</div>

@regis, Is there any way by which I can update my caddyfile using custom plugin same like we are using

> hooks.Filters.ENV\_TEMPLATE\_TARGETS.add\_item()

To make our custom Dockerfile persist.

However, I tried adding this content to my plugin by creating a ‘templates’ folder. Inside it, I created my plugin ( **config\_plugin** ) name folder, then a caddy folder, and finally, a Caddyfile.  
Here is my **config\_plugin.py** file look like,

```auto
template_folder = os.path.join(os.path.dirname( __file__ ), "templates")
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(template_folder)

hooks.Filters.ENV_TEMPLATE_TARGETS.add_item(("config_plugin/apps", "apps"))

```

Here is my Caddyfile to try it out:

```auto
{% block caddyfile-lms %}
{{ super() }}

# Custom route for LMS
handle_path /myhealthcheck {
    respond "OK LMS" 200
}
{% endblock %}

```

While running the command,

> tutor plugins enable config\_plugin

It shows me an error like an invalid template tag.

```auto
{% block caddyfile-lms %}
jinja2.exceptions.TemplateSyntaxError: Block names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.

```

Note: I am using **Quince** version.

---

<div class="post-metadata">

**Author:** ![joel.edwards](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/joel.edwards/32/3193_2.png) [@joel.edwards](https://discuss.openedx.org/u/joel.edwards)\
**Post date:** [May 7, 2025, 7:05am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/15 "2025-05-07T07:05:17Z")

</div>

@darsh_modi97 I’m not sure if I’m understanding correctly, but if all you want is for caddy to be able to return a 200 if it’s running then why not just directly patch the main Caddyfile? or is there more to your template/patch that I’m missing?

If all you want is to see a 200 response then try this:  
create file: `$(tutor plugins printroot)/caddyfile_server_up_test.py` (or whatever you want to name it)  
with the following contents:

```auto
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
    (
        "caddyfile-lms",
        """
# Custom route for LMS
handle_path /myhealthcheck {
    respond "OK LMS" 200
}

        """
    )
)

```

then run command `tutor plugins enable caddyfile_server_up_test` and restart the Caddy container with `tutor local restart caddy` and then you can go to `lms.domain.tld/myhealthcheck` and you should see your response of `OK LMS`  
optionally you can inspect the contents of `~/.local/share/tutor/env/apps/caddy/Caddyfile` and you should see your changes in there

---

<div class="post-metadata">

**Author:** ![darsh\_modi97](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@darsh\_modi97](https://discuss.openedx.org/u/darsh_modi97)\
**Post date:** [May 15, 2025, 6:42am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/16 "2025-05-15T06:42:51Z")

</div>

Hey @joel.edwards, Thanks for responding. I have a lot more content to add to my caddy file. I provided just an example of it. I found my solution by creating a new custom plugin to override my Caddyfile from the **apps/** folder itself after running

> tutor config save

Let me know if you want to know about that plugin. I can provide information about it.

---

<div class="post-metadata">

**Author:** ![joel.edwards](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/joel.edwards/32/3193_2.png) [@joel.edwards](https://discuss.openedx.org/u/joel.edwards)\
**Post date:** [May 15, 2025, 8:13am UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/17 "2025-05-15T08:13:15Z")

</div>

Thanks for the update @darsh_modi97 glad to hear you succeeded.  
I’m certain at least someone in the community would be grateful for your plugin, feel free to share if you’re willing 🙂

---

<div class="post-metadata">

**Author:** ![jakubkl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/jakubkl/32/9205_2.png) [@jakubkl](https://discuss.openedx.org/u/jakubkl)\
**Post date:** [March 16, 2026, 2:03pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/18 "2026-03-16T14:03:20Z")

</div>

Hey, I would really like to see how you managed to override it via a plugin as I’m also facing some issues. I have modifications to the Caddyfile that require more than current patches.

---

<div class="post-metadata">

**Author:** ![jakubkl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/jakubkl/32/9205_2.png) [@jakubkl](https://discuss.openedx.org/u/jakubkl)\
**Post date:** [March 16, 2026, 2:07pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/19 "2026-03-16T14:07:41Z")

</div>

The only way I managed to successfully overwrite the Caddyfile from scratch was by using a registered atexit function however that comes with limitations. Domains have to be hardcoded as it is (from what I know) impossible to retrive tutor env variables as that creates an infinite loop of recursive calls to tutor.

`import atexit`  
`def overwrite_final_caddyfile(){`  
` root_path = os.environ.get("TUTOR_ROOT", os.path.expanduser("~/.local/share/tutor"))`  
` caddy_file = os.path.join(root_path, "env", "apps", "caddy", "Caddyfile")`  
`....`  
`}`

`atexit.register(overwrite_final_caddyfile)`

---

<div class="post-metadata">

**Author:** ![joel.edwards](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/joel.edwards/32/3193_2.png) [@joel.edwards](https://discuss.openedx.org/u/joel.edwards)\
**Post date:** [March 16, 2026, 2:39pm UTC](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944/20 "2026-03-16T14:39:08Z")

</div>

Hi @jakubkl  
Are you able to provide any more detail about your intentions/goals and maybe some examples of what you’re trying to add to the caddyfile? eg: are you trying to modify the block of an existing entry, or to add new entries into the caddyfile?

[Next page](https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944.md?page=2)
