Adding timeout for client requests

Hi, I’m trying to add timeout to Caddyfile as follows:


  :443 {

    tls     /etc/caddy/agro-cert.pem /etc/caddy/agro-key.pem

    log {
            output file /var/log/caddylog.log

    root *  /var/www/html

    encode gzip

    route  /agroapi* {

       uri strip_prefix  /agroapi
       reverse_proxy  server:9000 {
              header_up  Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"


	servers {
		read_timeout 5m,
		read_header_timeout 5m,
		write_timeout 5m,
		idle_timeout  5m

    route  /api* {

       uri strip_prefix  /api
       reverse_proxy  express:3000 {
              header_up  Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"


    handle /share* {
            reverse_proxy express:3000

    header /agroapi ?Cache-Control
    header /share ?Cache-Control
    header /api ?Cache-Control


But keep getting this error:

/etc/Caddyfile:28: unrecognized directive: read_timeout

Please let me know what am I missing here?


servers is a global option, not a directive.

It needs to go in alongside debug at the top of your Caddyfile.

Replace this with handle_path /agroapi* {, which has built-in path prefix stripping logic, making you avoid the need for uri strip_prefix.

This doesn’t make sense. Strict-Transport-Security is a response header, but header_up manipulates request headers before sending the request to the proxy upstream. You probably want the header directive instead (outside or reverse_proxy) to manipulate the response headers.


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