Switching from nginx to caddy!

1. Caddy version (caddy version): v2

2. How I run Caddy:

a. System environment:

Windows Server 2019 Std

d. My complete Caddyfile or JSON config:

http:// {
    redir https://{host}{uri}
}

honeystalk.com:443 {
    encode gzip

    log {
        output file c:\apps\caddy\logs\site_access.log {
            roll true               # Rotate logs, enabled by default
            roll_size_mb 5          # Set max size 5 MB
            roll_gzip true          # Whether to compress rolled files
            roll_local_time true    # Use localhost time
            roll_keep 2             # Keep at most 2 log files
            roll_keep_days 7        # Keep log files for 7 days
        }
    }

    import lucee.conf

    handle /shared/* {
        header Access-Control-Allow-Headers "Content-Type"
        header Access-Control-Allow-Origin *
        root * d:/web/honeystalk.com/shared
        file_server
    }

    root * d:/web/honeystalk.com/site
    file_server

    rewrite * /index.cfm?{query}&path={path};

    tls /apps/nginx/conf/sites-enabled/certs/honeystalk.com.crt /apps/nginx/conf/sites-enabled/certs/honeystalk.com.key
}

*.honeystalk.com:443 {
    encode gzip

    log {
        output file c:\apps\caddy\logs\account_access.log {
            roll true               # Rotate logs, enabled by default
            roll_size_mb 5          # Set max size 5 MB
            roll_gzip true          # Whether to compress rolled files
            roll_local_time true    # Use localhost time
            roll_keep 2             # Keep at most 2 log files
            roll_keep_days 7        # Keep log files for 7 days
        }
    }

    import lucee.conf

    handle /shared/* {
        header Access-Control-Allow-Headers "Content-Type"
        header Access-Control-Allow-Origin *
        root * d:/web/honeystalk.com/shared
        file_server
    }

    root * d:/web/cogency.io/account
    file_server

   @cf path *.cfm *.cfc
   rewrite @cf {path}?sub={labels.2}&{query}
    
    tls /apps/nginx/conf/sites-enabled/certs/honeystalk.com.crt /apps/nginx/conf/sites-enabled/certs/honeystalk.com.key
}

3. The problem I’m having:

I am not sure how to port several pieces of code from nginx to caddy. Here they are

  1. The nginx server identifies the subdomain and stores it in the $sub param. Here is the nginx code
server_name ~^(?<sub>.+)\.honeystalk.com$;
  1. We always include the lucee.conf that handles all the ColdFusion requests
    include lucee.conf;

I am assuming the equivalent command in caddy would be import lucee.conf

  1. Here is the content of lucee.conf that needs to be ported over to caddy
####   lucee.conf   ####

location ~ /META-INF/ { return 404; }
location ~ /WEB-INF/ { return 404; }
location ~ \.config$ { return 404; }
location ~ /\. { return 404; }       ## e.g. .htaccess, .gitignore etc.
location ~ ~$ { return 404; }
location ~ \.(aspx|php|jsp|cgi)$ { return 410; } #410 means "don’t try this again" which should be better than a 404
location /images/companies { location ~ (\.cfm|\.cfc)$ { return 403; } } #disable the execution of CF files in any directory containing user uploads

# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
	# Some basic cache-control for static files to be sent to the browser
	expires max;
	add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log  off;
}

# block the lucee-context except for certain ip
location ~* /lucee/ {
	# allow 10.0.0.157;
	# deny all;
	include lucee-proxy.conf;
}

location ~* /lucee-server {
	return 404;
}

# block requests for Application.cfc/cfm
location ~* application.cf[mc]$ {
	return 404;
}

# match cfm or cfc files and proxy them off to tomcat
location ~* (\.cfm|\.cfc)$ {
	import lucee-proxy.conf;

	if ($sub){
		rewrite ^/(.*\.cf[m|c])$ /$1?sub=$sub&$args? break; #lets append the subdomain to the request
	}
}

# set the default document to index.html or index.cfm
index index.html index.cfm;

The most important bit of this code is the part that proxies the request to tomcat

# match cfm or cfc files and proxy them off to tomcat
location ~* (\.cfm|\.cfc)$ {
	import lucee-proxy.conf;
        
        # $sub comes from the server_name match up
	if ($sub){
		rewrite ^/(.*\.cf[m|c])$ /$1?sub=$sub&$args? break; #lets append the subdomain to the request
	}
}

Also, as you noticed inside lucee.conf we include lucee-proxy.conf

####   lucee-proxy.conf   ####

reverse_proxy http://127.0.0.1:8888;

expires epoch; #do not cache

proxy_read_timeout 100s;
proxy_redirect off;

# include standard proxy headers
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# add headers for mod_cfml to do its work
proxy_set_header X-Tomcat-DocRoot $document_root;
proxy_set_header X-ModCFML-SharedKey <shared-key>;

if ($lucee_context = false) {
	set $lucee_context $document_root;
}
proxy_set_header X-Webserver-Context $lucee_context;

set $pathinfo "";

# set the custom path_info header
proxy_set_header XAJP-PATH-INFO $pathinfo;

error_page      404     /404.cfm?uri=$request_uri;  ## direct errors to lucee and pass original uri
error_page      403     /404.cfm?uri=$request_uri;  ## show forbidden as innocent 404
error_page      500     /500.cfm?uri=$request_uri;
error_page      503     /503.cfm?uri=$request_uri;

5. What I already tried:

I have at this for more than a week, I think i am ready to ask for some help from the community!

6. Links to relevant resources:

Caddy has {labels.*} placeholders which let you grab a specific part of the subdomain, indexed starting from the right. Here you’d use {labels.2} to grab the subdomain (whereas {labels.0} would be com)

You’ll probably need to use a wildcard site address, which may also mean you want to use a wildcard cert. It depends what you’re doing though.

Yeah, the Caddyfile adapter allows you to pull in common bits of config from another file or from a snippet:

Caddy’s file_server takes the defined root then appends the current request path to it, so for a request like /shared/something.html then the final path would be d:/web/honeystalk.com/shared/shared/something.html. Notice the double /shared. Probably not what you want.

I think you’ll probably want to use handle_path here, which has built-in path prefix stripping logic, so it would remove the /shared bit from the request path before passing it onto its handlers within.

Don’t use semicolons in the Caddyfile.

You won’t need any of this stuff for Caddy, since Caddy already sets these headers appropriately, automatically:

For this, you’ll want to use the handle_errors directive, which allows you to control how errors in Caddy are rendered. Keep in mind that 4xx and 5xx status codes received from reverse_proxy upstreams are not considered errors by Caddy and will be directly written to the response. If you need to rewrite those as well, then you can use the handle_response feature of the reverse_proxy directive to do some handling based on the status code or response header content.

1 Like

@francislavoie Wow! You guys rock!! Thank you for the awesome and immediate support !!!

One quick question… that is a bit off topic here but as important to me while switching over. I have my DNS managed by GoDaddy and I found a plugin GitHub - caoyongzheng/caddy-dns-godaddy: This package contains a DNS provider module for Caddy. It can be used to manage DNS records with DNSPOD accounts. to allow for tls support but I am not seeing that plugin in the official list to add to the build. Is that something that could be done soonish? ( like today… lol )

There’s been an issue open for that:

I think it’s up to the maintainer of that plugin to reach out to @matt to get it moved to the caddy-dns org. They seem to have left it inactive though.

:man_shrugging:

If it’s implemented properly, it should probably still work if you build from that repo, if you need it.

1 Like

@francislavoie what is the caddy equivalent for specifying the default index file?

in nginx its index index.html

That’s already Caddy’s default for file_server.

@francislavoie I can’t seem to get my ColdFusion working with Caddy. There are no errors in the console. Here is the output.

2022/01/22 02:07:37.471 INFO    using adjacent Caddyfile
2022/01/22 02:07:37.484 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2022/01/22 02:07:37.500 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2022/01/22 02:07:37.507 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc00033a1c0"}
2022/01/22 02:07:37.524 INFO    http    skipping automatic certificate management because one or more matching certificates are already load
        {"domain": "honeystalk.io", "server_name": "srv0"}
2022/01/22 02:07:37.525 INFO    http    skipping automatic certificate management because one or more matching certificates are already load
        {"domain": "*.honeystalk.io", "server_name": "srv0"}
2022/01/22 02:07:37.526 INFO    http    skipping automatic certificate management because one or more matching certificates are already load
        {"domain": "www.honeystalk.io", "server_name": "srv0"}
2022/01/22 02:07:37.527 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2022/01/22 02:07:37.528 INFO    http    server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv1", "http_port": 80}
2022/01/22 02:07:37.530 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\Administrator\\AppData\\Roaming\\Caddy\\autosave.json"}
2022/01/22 02:07:37.542 INFO    serving initial configuration
2022/01/22 02:07:37.540 INFO    tls     cleaning storage unit   {"description": "FileStorage:C:\\Users\\Administrator\\AppData\\Roaming\\Caddy"}
2022/01/22 02:07:37.546 INFO    tls     finished cleaning storage units

Here is the current setup.

Caddyfile

http:// {
    redir https://{host}{uri}
}

honeystalk.io:443 {
    encode gzip

    log {
        output file logs/honeystalk_site_access.log
        format json
    }

    import lucee.conf

    handle_path /shared/* {
        header Access-Control-Allow-Headers "Content-Type"
        header Access-Control-Allow-Origin *
        root * d:/web/honeystalk.io/shared
        file_server
    }

    root * d:/web/honeystalk.io/site
    file_server

    rewrite * /index.cfm?{query}&path={path};

    tls /apps/nginx/conf/sites-enabled/certs/honeystalk_io.crt /apps/nginx/conf/sites-enabled/certs/honeystalk_io.key
}

www.honeystalk.io:443 {
    redir https://honeystalk.io{uri} permanent
}

*.honeystalk.io:443 {
    encode gzip

    log {
        output file logs/honeystalk_account_access.log
        format json
    }

    import lucee.conf

    handle_path /shared/* {
        header Access-Control-Allow-Headers "Content-Type"
        header Access-Control-Allow-Origin *
        root * d:/web/honeystalk.io/shared
        file_server
    }

    root * d:/web/honeystalk.io/account
    file_server

    rewrite * /index.cfm?{query}&path={path};

    tls /apps/nginx/conf/sites-enabled/certs/honeystalk_io.crt /apps/nginx/conf/sites-enabled/certs/honeystalk_io.key
}

lucee.conf

# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
@static {
  file
  path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff
}
header @static Cache-Control max-age=5184000

handle /lucee/* {
	# allow 10.0.0.157;
	# allow 216.239.169.122;
	# deny all;
	import lucee-proxy.conf
}

handle /lucee-server/* {
	respond 404
}

@acf path application.cfm application.cfc
handle @acf {
	respond 404
}

@cf path *.cfm *.cfc
handle @cf {
	import lucee-proxy.conf

	rewrite @cf {path}?sub={labels.2}&{query}
}

file_server {
	index index.html index.cfm
}

lucee-proxy.conf

handle {
	reverse_proxy http://127.0.0.1:8888
}

# include standard proxy headers
header {
	Host $host
	X-Real-IP $remote_addr
	X-Forwarded-For $proxy_add_x_forwarded_for
	X-Forwarded-Proto $scheme

	header X-Tomcat-DocRoot $document_root;
	header X-ModCFML-SharedKey <sharedkey>;

	# set the custom path_info header
	header XAJP-PATH-INFO "";
}

I noticed a couple of things… not sure how relevant

  1. In the logs it shows 127.0.0.1:2019 I am not sure where that is coming from. The only reverse_proxy specified is inside the lucee-proxy.conf file
  2. Another weird thing in the logs server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server – Does that mean the user will not be redirected from http to https?

Please let me know if you can spot anything in the configs. :pray:

Oh, here is the log file that got generated once i visited demo.honeystalk.io

{"level":"info","ts":1642817704.3725457,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Sec-Ch-Ua-Platform":["\"Windows\""],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Accept-Language":["en-US,en;q=0.9"],"Sec-Ch-Ua-Mobile":["?0"],"Upgrade-Insecure-Requests":["1"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Dest":["document"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Cache-Control":["max-age=0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.1142554,"size":96,"status":302,"resp_headers":{";":[""],"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"Server":["Caddy"],"Host":["$host"],"X-Real-Ip":["$remote_addr"],"Content-Length":["96"],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"X-Forwarded-Proto":["$scheme"],"Location":["/"],"Content-Type":["text/html;charset=UTF-8"],"Header":["XAJP-PATH-INFO"],"Set-Cookie":["CFID=a18ee402-685f-4722-b06a-a661a31c1804;Path=/","CFTOKEN=0;Path=/"],"P3p":["CP=\"CAO PSA OUR\""],"X-Frame-Options":["SAMEORIGIN"],"Access-Control-Allow-Origin":["*"]}}
{"level":"info","ts":1642817704.4160018,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Cache-Control":["max-age=0"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Dest":["document"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.9"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.0317365,"size":96,"status":302,"resp_headers":{"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"Location":["/"],"Header":["XAJP-PATH-INFO"],"X-Forwarded-Proto":["$scheme"],"Content-Length":["96"],"P3p":["CP=\"CAO PSA OUR\""],";":[""],"X-Frame-Options":["SAMEORIGIN"],"Access-Control-Allow-Origin":["*"],"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"Server":["Caddy"],"X-Real-Ip":["$remote_addr"],"Host":["$host"],"Content-Type":["text/html;charset=UTF-8"]}}
{"level":"info","ts":1642817704.4423685,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Cache-Control":["max-age=0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Sec-Fetch-Site":["none"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Sec-Fetch-Mode":["navigate"],"Accept-Language":["en-US,en;q=0.9"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.0198233,"size":96,"status":302,"resp_headers":{"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"Header":["XAJP-PATH-INFO"],"Host":["$host"],"Content-Length":["96"],"P3p":["CP=\"CAO PSA OUR\""],"X-Frame-Options":["SAMEORIGIN"],"Server":["Caddy"],";":[""],"Content-Type":["text/html;charset=UTF-8"],"X-Real-Ip":["$remote_addr"],"Access-Control-Allow-Origin":["*"],"Location":["/"],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"X-Forwarded-Proto":["$scheme"]}}
{"level":"info","ts":1642817704.4684474,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Sec-Fetch-Dest":["document"],"Accept-Language":["en-US,en;q=0.9"],"Cache-Control":["max-age=0"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Sec-Ch-Ua-Mobile":["?0"],"Accept-Encoding":["gzip, deflate, br"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.0205055,"size":96,"status":302,"resp_headers":{"Access-Control-Allow-Origin":["*"],"Host":["$host"],"X-Forwarded-Proto":["$scheme"],"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"P3p":["CP=\"CAO PSA OUR\""],"Header":["XAJP-PATH-INFO"],"X-Real-Ip":["$remote_addr"],"X-Frame-Options":["SAMEORIGIN"],"Location":["/"],"Server":["Caddy"],"Content-Length":["96"],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],";":[""],"Content-Type":["text/html;charset=UTF-8"]}}
{"level":"info","ts":1642817704.4941266,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Sec-Ch-Ua-Mobile":["?0"],"Cache-Control":["max-age=0"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Dest":["document"],"Accept-Language":["en-US,en;q=0.9"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.0209584,"size":96,"status":302,"resp_headers":{"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"Header":["XAJP-PATH-INFO"],"X-Frame-Options":["SAMEORIGIN"],"Access-Control-Allow-Origin":["*"],"Host":["$host"],"X-Real-Ip":["$remote_addr"],";":[""],"Content-Type":["text/html;charset=UTF-8"],"Content-Length":["96"],"P3p":["CP=\"CAO PSA OUR\""],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"X-Forwarded-Proto":["$scheme"],"Server":["Caddy"],"Location":["/"]}}
{"level":"info","ts":1642817704.5200074,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Sec-Fetch-Site":["none"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Ch-Ua-Mobile":["?0"],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Accept-Encoding":["gzip, deflate, br"],"Cache-Control":["max-age=0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Mode":["navigate"],"Accept-Language":["en-US,en;q=0.9"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.0195973,"size":96,"status":302,"resp_headers":{"Host":["$host"],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"Access-Control-Allow-Origin":["*"],"Header":["XAJP-PATH-INFO"],"X-Forwarded-Proto":["$scheme"],"Content-Length":["96"],"Server":["Caddy"],"Location":["/"],"X-Real-Ip":["$remote_addr"],";":[""],"Content-Type":["text/html;charset=UTF-8"],"P3p":["CP=\"CAO PSA OUR\""],"X-Frame-Options":["SAMEORIGIN"]}}
{"level":"info","ts":1642817704.543278,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.0.0.172:58007","proto":"HTTP/2.0","method":"GET","host":"demo.honeystalk.io","uri":"/","headers":{"Cache-Control":["max-age=0"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"Sec-Ch-Ua-Mobile":["?0"],"Accept-Language":["en-US,en;q=0.9"],"Cookie":["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Dest":["document"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""],"Sec-Ch-Ua-Platform":["\"Windows\""],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.honeystalk.io"}},"common_log":"10.0.0.172 - - [21/Jan/2022:21:15:04 -0500] \"GET / HTTP/2.0\" 302 96","user_id":"","duration":0.017685,"size":96,"status":302,"resp_headers":{"Date":["Sat, 22 Jan 2022 02:15:04 GMT"],"X-Frame-Options":["SAMEORIGIN"],"Header":["XAJP-PATH-INFO"],"Location":["/"],"X-Forwarded-For":["$proxy_add_x_forwarded_for"],"X-Real-Ip":["$remote_addr"],";":[""],"P3p":["CP=\"CAO PSA OUR\""],"Server":["Caddy"],"X-Forwarded-Proto":["$scheme"],"Content-Type":["text/html;charset=UTF-8"],"Content-Length":["96"],"Access-Control-Allow-Origin":["*"],"Host":["$host"]}}

Remove these lines. They’re not useful, and are probably breaking things. Caddy doesn’t do variables this way either. Caddy uses placeholders which take the form of a namespaced key enclosed in { }.

That is Caddy’s admin endpoint. It’s what allows for online config changes, graceful reloading, etc. See the docs.

No, this is saying that you defined your own http:// site block so Caddy won’t make it’s own.

You can actually remove yours, it’s not useful, Caddy will set up HTTP->HTTPS redirects automatically.

You also don’t need to specify port :443 on each of your site blocks. Caddy is HTTPS by default already.

I recommend enabling the debug global option to see additional details in the logs about what Caddy is doing. It’ll help you trace it.

One thing to note, the Caddyfile is not executed top-down in the order you write the config. Directives are sorted according to a predetermined order as documented here in the docs:

Using the imports in your config, it becomes harder to follow in which order things will end up being run.

You can use handle (and handle_path) blocks to group up mutually exclusive routes – only the first matched handle will run.

If you use handle blocks, you’ll probably want to use them everywhere. Notably, your root+file_server at the top level of your config should probably be in a handle.

I’m your proxy file, if you want to send those headers to your backend, you need to use the header_up subdirective of reverse_proxy, and not the header directive which manipulates the response headers.

@francislavoie It almost looks like the redirect is not getting terminated?

# caddy_windows_amd64 run
2022/01/22 02:58:55.002 INFO    using adjacent Caddyfile
2022/01/22 02:58:55.016 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2022/01/22 02:58:55.034 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2022/01/22 02:58:55.041 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc000334770"}
2022/01/22 02:58:55.044 DEBUG   tls.cache       added certificate to cache      {"subjects": ["*.honeystalk.io", "honeystalk.io"], "expiration": "2022/09/13 23:59:59.000", "managed": false, "issuer_key": "", "hash": "d1babd3aa9eade49bf1aa2279af5f632967627815410f39e03f7a52e2d92098a", "cache_size": 1, "cache_capacity": 10000}
2022/01/22 02:58:55.049 INFO    http    skipping automatic certificate management because one or more matching certificates are already loaded  {"domain": "www.honeystalk.io", "server_name": "srv0"}
2022/01/22 02:58:55.051 INFO    http    skipping automatic certificate management because one or more matching certificates are already loaded  {"domain": "honeystalk.io", "server_name": "srv0"}
2022/01/22 02:58:55.053 INFO    http    skipping automatic certificate management because one or more matching certificates are already loaded  {"domain": "*.honeystalk.io", "server_name": "srv0"}
2022/01/22 02:58:55.055 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2022/01/22 02:58:55.063 DEBUG   http    starting server loop    {"address": "[::]:80", "http3": false, "tls": false}
2022/01/22 02:58:55.065 DEBUG   http    starting server loop    {"address": "[::]:443", "http3": false, "tls": true}
2022/01/22 02:58:55.067 INFO    tls     cleaning storage unit   {"description": "FileStorage:C:\\Users\\Administrator\\AppData\\Roaming\\Caddy"}
2022/01/22 02:58:55.068 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\Administrator\\AppData\\Roaming\\Caddy\\autosave.json"}
2022/01/22 02:58:55.070 INFO    tls     finished cleaning storage units
2022/01/22 02:58:55.070 INFO    serving initial configuration
2022/01/22 02:59:17.335 DEBUG   tls.handshake   no matching certificate; will choose from all certificates      {"identifier": "demo.honeystalk.io"}
2022/01/22 02:59:17.341 DEBUG   tls.handshake   choosing certificate    {"identifier": "demo.honeystalk.io", "num_choices": 1}
2022/01/22 02:59:17.342 DEBUG   tls.handshake   custom certificate selection results    {"identifier": "demo.honeystalk.io", "subjects": ["*.honeystalk.io", "honeystalk.io"], "managed": false, "issuer_key": "", "hash": "d1babd3aa9eade49bf1aa2279af5f632967627815410f39e03f7a52e2d92098a"}
2022/01/22 02:59:17.344 DEBUG   tls.handshake   matched certificate in cache    {"subjects": ["*.honeystalk.io", "honeystalk.io"], "managed": false, "expiration": "2022/09/13 23:59:59.000", "hash": "d1babd3aa9eade49bf1aa2279af5f632967627815410f39e03f7a52e2d92098a"}
2022/01/22 02:59:17.367 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Sec-Fetch-User": ["?1"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Ch-Ua-Mobile": ["?0"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Dest": ["document"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?path=%2F;"}
2022/01/22 02:59:17.373 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?path=%2F;", "headers": {"Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Sec-Fetch-User": ["?1"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Ch-Ua-Mobile": ["?0"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?sub=demo&path=%2F;"}
2022/01/22 02:59:17.485 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "127.0.0.1:8888", "duration": 0.1008931, "request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?sub=demo&path=%2F;", "headers": {"Sec-Ch-Ua-Mobile": ["?0"], "X-Forwarded-For": ["10.0.0.172"], "X-Forwarded-Proto": ["https"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Sec-Fetch-User": ["?1"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "headers": {"Content-Length": ["96"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "P3p": ["CP=\"CAO PSA OUR\""], "X-Frame-Options": ["SAMEORIGIN"], "Access-Control-Allow-Origin": ["*"], "Location": ["/"], "Content-Type": ["text/html;charset=UTF-8"]}, "status": 302}
2022/01/22 02:59:17.492 INFO    http.log.access.log1    handled request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"Sec-Ch-Ua-Platform": ["\"Windows\""], "Sec-Fetch-User": ["?1"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Ch-Ua-Mobile": ["?0"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "common_log": "10.0.0.172 - - [21/Jan/2022:21:59:17 -0500] \"GET / HTTP/2.0\" 302 96", "user_id": "", "duration": 0.123555, "size": 96, "status": 302, "resp_headers": {"Access-Control-Allow-Origin": ["*"], "P3p": ["CP=\"CAO PSA OUR\""], "Header_up": ["XAJP-PATH-INFO"], "X-Frame-Options": ["SAMEORIGIN"], "Location": ["/"], "Content-Type": ["text/html;charset=UTF-8"], "Content-Length": ["96"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "Server": ["Caddy"], ";": [""]}}
2022/01/22 02:59:17.502 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-User": ["?1"], "Sec-Ch-Ua-Mobile": ["?0"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?path=%2F;"}
2022/01/22 02:59:17.506 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?path=%2F;", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-User": ["?1"], "Sec-Ch-Ua-Mobile": ["?0"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "Accept-Language": ["en-US,en;q=0.9"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?sub=demo&path=%2F;"}
2022/01/22 02:59:17.533 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "127.0.0.1:8888", "duration": 0.0229066, "request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?sub=demo&path=%2F;", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-User": ["?1"], "Sec-Ch-Ua-Mobile": ["?0"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "X-Forwarded-Proto": ["https"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "X-Forwarded-For": ["10.0.0.172"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "headers": {"X-Frame-Options": ["SAMEORIGIN"], "Access-Control-Allow-Origin": ["*"], "Location": ["/"], "Content-Type": ["text/html;charset=UTF-8"], "Content-Length": ["96"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "P3p": ["CP=\"CAO PSA OUR\""]}, "status": 302}
2022/01/22 02:59:17.539 INFO    http.log.access.log1    handled request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-User": ["?1"], "Sec-Ch-Ua-Mobile": ["?0"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "Accept-Language": ["en-US,en;q=0.9"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "common_log": "10.0.0.172 - - [21/Jan/2022:21:59:17 -0500] \"GET / HTTP/2.0\" 302 96", "user_id": "", "duration": 0.0369694, "size": 96, "status": 302, "resp_headers": {"Server": ["Caddy"], ";": [""], "Header_up": ["XAJP-PATH-INFO"], "Location": ["/"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "Access-Control-Allow-Origin": ["*"], "Content-Type": ["text/html;charset=UTF-8"], "Content-Length": ["96"], "P3p": ["CP=\"CAO PSA OUR\""], "X-Frame-Options": ["SAMEORIGIN"]}}
2022/01/22 02:59:17.562 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Ch-Ua-Mobile": ["?0"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua-Platform": ["\"Windows\""]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?path=%2F;"}
2022/01/22 02:59:17.567 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?path=%2F;", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Ch-Ua-Mobile": ["?0"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?sub=demo&path=%2F;"}
2022/01/22 02:59:17.600 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "127.0.0.1:8888", "duration": 0.0252181, "request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?sub=demo&path=%2F;", "headers": {"X-Forwarded-For": ["10.0.0.172"], "Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Ch-Ua-Mobile": ["?0"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "X-Forwarded-Proto": ["https"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "headers": {"Content-Type": ["text/html;charset=UTF-8"], "Content-Length": ["96"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "P3p": ["CP=\"CAO PSA OUR\""], "X-Frame-Options": ["SAMEORIGIN"], "Access-Control-Allow-Origin": ["*"], "Location": ["/"]}, "status": 302}
2022/01/22 02:59:17.610 INFO    http.log.access.log1    handled request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Ch-Ua-Mobile": ["?0"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "common_log": "10.0.0.172 - - [21/Jan/2022:21:59:17 -0500] \"GET / HTTP/2.0\" 302 96", "user_id": "", "duration": 0.0486971, "size": 96, "status": 302, "resp_headers": {"Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "X-Frame-Options": ["SAMEORIGIN"], "Content-Type": ["text/html;charset=UTF-8"], "Server": ["Caddy"], ";": [""], "Header_up": ["XAJP-PATH-INFO"], "Content-Length": ["96"], "P3p": ["CP=\"CAO PSA OUR\""], "Access-Control-Allow-Origin": ["*"], "Location": ["/"]}}
2022/01/22 02:59:17.627 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/", "headers": {"Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Fetch-Mode": ["navigate"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?path=%2F;"}
2022/01/22 02:59:17.632 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?path=%2F;", "headers": {"Sec-Fetch-Mode": ["navigate"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "method": "GET", "uri": "/index.cfm?sub=demo&path=%2F;"}
2022/01/22 02:59:17.660 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "127.0.0.1:8888", "duration": 0.0208025, "request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?sub=demo&path=%2F;", "headers": {"Cache-Control": ["max-age=0"], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Sec-Fetch-Mode": ["navigate"], "X-Forwarded-For": ["10.0.0.172"], "X-Forwarded-Proto": ["https"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "headers": {"Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "P3p": ["CP=\"CAO PSA OUR\""], "X-Frame-Options": ["SAMEORIGIN"], "Access-Control-Allow-Origin": ["*"], "Location": ["/"], "Content-Type": ["text/html;charset=UTF-8"], "Content-Length": ["96"]}, "status": 302}

I am seeing this a bunch of times

http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "127.0.0.1:8888", "duration": 0.1008931, "request": {"remote_addr": "10.0.0.172:58255", "proto": "HTTP/2.0", "method": "GET", "host": "demo.honeystalk.io", "uri": "/index.cfm?sub=demo&path=%2F;", "headers": {"Sec-Ch-Ua-Mobile": ["?0"], "X-Forwarded-For": ["10.0.0.172"], "X-Forwarded-Proto": ["https"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": ["_ga=GA1.2.333704257.1612785673; LUCEE_ADMIN_LANG=en; LUCEE_ADMIN_LASTPAGE=overview; CFID=a18ee402-685f-4722-b06a-a661a31c1804; CFTOKEN=0; crisp-client%2Fsession%2F77a8a0fa-b7c3-4f50-8461-b879adfe8388=session_b9596d22-c319-40ca-a6f1-3cda770bd980"], "Sec-Ch-Ua-Platform": ["\"Windows\""], "Sec-Fetch-User": ["?1"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4867, "proto": "h2", "proto_mutual": true, "server_name": "demo.honeystalk.io"}}, "headers": {"Content-Length": ["96"], "Date": ["Sat, 22 Jan 2022 02:59:17 GMT"], "P3p": ["CP=\"CAO PSA OUR\""], "X-Frame-Options": ["SAMEORIGIN"], "Access-Control-Allow-Origin": ["*"], "Location": ["/"], "Content-Type": ["text/html;charset=UTF-8"]}, "status": 302}

Looks like your rewrite is not correct.

Please keep in mind, like I said, that Caddy’s config is not executed in the order you wrote it in the config.

@francislavoie I have a couple of issues I need your help with

  1. I am not understanding why this code to trigger a rewrite is not working.
root * d:/web/honeystalk.io/account

    @try_files {
        not path /cfc/* /js/* /css/*
        file {
            try_files {path} {path}/ /index.cfm?path={path}
        }
    }
    rewrite @try_files {http.matchers.file.relative}

I am still getting this error msg when trying to go to https://demo.honeystalk.io/boards

2022/01/23 04:48:43.146 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "d:/web/honeystalk.io/account", "request_path": "/boards", "result": "d:\\web\\honeystalk.io\\account\\boards"}

I was under the impression that any file/ directory that does not exist will get rewritten to /index.cfm..


  1. When the default index gets applied … meaning when I go to https://demo.honeystalk.io I get served the file content of the index.cfm file instead of the file getting run through the proxy

I do have this code in place that is supposed to catch any .cfm files and run them through the reverse proxy

@cf path *.cfm *.cfc
handle @cf {
	import lucee-proxy.conf

	rewrite @cf {path}?sub={labels.2}&{query}
}

The try_files directive looks for a file on disk with the literal input you gave it. So it will look for a file that looks like /index.cfm?path=/boards which obviously will not exist. So instead, you need to do this:

    @try_files {
        not path /cfc/* /js/* /css/*
        not file {path} {path}/
    }
    rewrite @try_files /index.cfm?path={path}

Basically, since you’re using file_server, the {path}/ that rewrite isn’t necessary because file_server will perform a redirect to add / if the file was a directory, to canonicalize the request path.

So to fix it, the actual rewrite destination should be moved to the actual rewrite, and only rewrite when the path isn’t one that shouldn’t be touched.

It is a fair point that maybe try_files should support a query part, but it might be kinda tricky to implement.

It depends on how the handlers get sorted in your config.

Try running caddy adapt --pretty --config <path-to-Caddyfile> to see the JSON output, which will show you the actual order your Caddyfile will execute in (top-to-bottom).

@francislavoie So, after tinkering with this for a while I got a working solution to the two problems

@redirected {
        not path /cfc/* /js/* /css/*
        path *
    }
    rewrite @redirected /index.cfm?path={path}

By doing this I realized that path needed to be set to * b/c it would cover every scenario except for the ones mentioned in not path! So this is working well, and it also took care of the default index issue.

The only other item on my list to solve is to figure out how to submit a PR to the libdns repo for the godaddy provider ( I forked the original abandoned repo LOL ) and get it added to the official Caddy builds. …seems like another herculean task :sweat_smile: :sweat_smile: :sweat_smile:

Once that is done, I will be able to deploy the solution to production!!

I don’t understand. Don’t you want that rewrite to apply only to files that don’t exist on disk? That’s what the file matcher would help you do.

Make sure to fill out the issue you opened in GoDaddy Provider · Issue #57 · libdns/libdns · GitHub with details of the implementation repos, and he can transfer them to the libdns and caddy-dns org.

This won’t happen. We don’t bundle any third-party plugins (including DNS plugins) in the official distributions of Caddy.

You can always make a custom build with the plugin, or download a build from the Download Caddy page once it’s been registered on the site.

Yeah, I meant to be added to the list of plugins. =)

No, I actually do want for everything except for the specific folders to be rewritten. So this is exactly what I needed!

@francislavoie Ok, tried converting my last config file for the websockets. Here is the re-written caddy code

ws-dev.honeystalk.io {
    encode gzip

    # log {
    #     output file logs/honeystalk_site_access.log
    #     format json
    # }

    import ../security-headers.conf

    handle_path /ws {
        header Connection *Upgrade*
        header Upgrade websocket

        reverse_proxy http://127.0.0.1:7777/ws
    }

    handle_path /broadcast {
        reverse_proxy http://127.0.0.1:7777/broadcast
    }

    handle {
        reverse_proxy http://127.0.0.1:7777
    }

    root * d:/web/ws.honeystalk.io

    tls c:/apps/nginx/conf/sites-enabled/certs/honeystalk_io.crt c:/apps/nginx/conf/sites-enabled/certs/honeystalk_io.key
}

I can’t seem to figure out why I keep on getting this error

# caddy_windows_amd64 run
2022/01/24 03:48:20.922 INFO    using adjacent Caddyfile
run: adapting config using caddyfile: parsing caddyfile tokens for 'handle_path': c:\apps\caddy\confs\ws.honeystalk.io.conf:16 - Error during parsing: parsing caddyfile tokens for 'reverse_proxy': c:\apps\caddy\confs\ws.honeystalk.io.conf:15 - Error during parsing: for now, URLs for proxy upstreams only support scheme, host, and port components

Line 16 is for this block

handle_path /ws {
        header Connection *Upgrade*
        header Upgrade websocket

        reverse_proxy http://127.0.0.1:7777/ws
    }

Caddy doesn’t support having a request path in the reverse_proxy upstream, it doesn’t support doing a simultaneous rewrite of the request – there’s the rewrite directive if you need that.

But in this case, I don’t think you need either of your extra handle blocks there. Caddy supports Websockets out of the box. Just do a single reverse_proxy 127.0.0.1:7777 and it will work for all 3 cases (broadcast, ws, everything else). No need to use handle_path to strip the path only to immediately re-add it. And no need for those header lines (remember, those manipulate response headers, not request headers, anyway).

Also there’s no use to setting root in here since you’re always proxying. That’s only useful if you’re using the file server or file matcher or PHP fastcgi, which need to look at files on disk.

1 Like

@francislavoie WOW this is SUPER awesome! I am now literally having just this one line reverse_proxy 127.0.0.1:7777!!! Way to go!

On a separate note, I am not fully understanding how to create a PR on libdns :frowning: From what I am reading I need to create a fork off of libdns repo and then open a pull request back to the upstream repo … is that the gist?

Ok, the PR is submitted!

2 Likes