Using caddy to output the contents of a live text file or log

1. Output of caddy version: v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

systemctl start caddy
using official systemd unit file with an addition to send an email on failure

a. System environment:

systemd controlled, ubuntu 22.02

b. Command:

systemctl start caddy

c. Service/unit/compose file:

  GNU nano 6.2                              /etc/systemd/system/caddy.service                                        # caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
OnFailure=crashmailserv@%n.service

StartLimitIntervalSec=10
StartLimitBurst=5

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
ExecStartPost=+/bin/systemctl start upmailserv@%n.service
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
Environment=DO_AUTH_TOKEN=redacted
Restart=always

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

(gen) {
	encode gzip
	uri strip_suffix .html
	try_files {path} {path}.php {path}.html index.php index.html =404
	php_fastcgi unix//var/run/php/php8.1-fpm.sock {
	try_files {path} {path}.php index.php =404
	}
	file_server
	handle_errors {
		rewrite * /{http.error.status_code}
		reverse_proxy https://http.cat {
			header_up Host http.cat
		}
	}
	log {
		format console
		output file /var/log/caddy.log {
			roll_size 25mb
			roll_keep 20
			roll_keep_for 720h
		}
	}
}

(e-gen) {
	encode gzip
	uri strip_suffix .html
	try_files {path} {path}.php {path}.html index.php index.html
	php_fastcgi unix//var/run/php/php8.1-fpm.sock {
	try_files {path} {path}.php index.php
	}
	file_server
	respond /seed/* "Gone" 410 {
	close
	}
	respond /nh/* "Gone" 410 {
	close
	}
	handle_errors {
		rewrite * /{http.error.status_code}
		reverse_proxy https://http.cat {
			header_up Host http.cat
		}
	}
	log {
		format console
		output file /var/log/caddy.log {
			roll_size 25mb
			roll_keep 20
			roll_keep_for 720h
		}
	}
}

(dns) {
	tls {
		dns digitalocean redacted
	}
}

(header-gen) {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"
		X-XSS-Protection "1; mode=block"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
	}
}

(bfm-header) {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"
		X-XSS-Protection "1; mode=block"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
		Cache-Control: no-cache, must-revalidate
	}
}

eiphax.tech {
	header {
		Strict-Transport-Security "max-age=31536000; preload"
		X-XSS-Protection "1; mode=block"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
	}
	root * /var/www/eipmain/webroot
	import e-gen
}

facts.eiphax.tech {
	import header-gen
	root * /var/www/eipmain/facts
	import gen
}

laundry.eiphax.tech {
	import header-gen
	root * /var/www/eipmain/webroot/laundry
	import gen
}

soultrader.net.au {
	import header-gen
	root * /var/www/st
	import gen
}

blog.eiphax.tech {
	import header-gen
	root * /var/www/blog
	import gen
}

bytes.eiphax.tech {
	import header-gen
	root * /var/www/bytes
	import gen
}

album.eiphax.tech {
	import header-gen
	root * /var/www/lychee/public
	import gen
}

bin.eiphax.tech {
	import header-gen
	root * /var/www/eipbin
	import gen
}

3ds.eiphax.tech {
@ytbad {
    header Referer *youtube.com*
}
@ytbad2 {
    header Referer *youtu.be*
}
    rewrite @ytbad /youtube.php
    rewrite @ytbad2 /youtube.php
	import header-gen
	root * /var/www/eipmain/3ds
	import gen
}

http://wiiu.eiphax.tech {
@ytbad {
    header Referer *youtube.com*
}
@ytbad2 {
    header Referer *youtu.be*
}
    rewrite @ytbad /youtube.php
    rewrite @ytbad2 /youtube.php
	root * /var/www/eipmain/wiiu
	import gen
}

https://wiiu.eiphax.tech {
@ytbad {
    header Referer *youtube.com*
}
@ytbad2 {
    header Referer *youtu.be*
}
    rewrite @ytbad /youtube.php
    rewrite @ytbad2 /youtube.php
	root * /var/www/eipmain/wiiu/resources
	import gen
	import header-gen
}

nx.eiphax.tech {
@ytbad {
    header Referer *youtube.com*
}
@ytbad2 {
    header Referer *youtu.be*
}
    rewrite @ytbad /youtube.php
    rewrite @ytbad2 /youtube.php
	import header-gen
	root * /var/www/eipmain/nx
	import gen
}

nintendohomebrew.com {
	header {
		Strict-Transport-Security "max-age=31536000; preload"
		X-XSS-Protection "1; mode=block"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "DENY"
	}
	handle_errors {
		rewrite * /{http.error.status_code}
		reverse_proxy https://http.cat {
			header_up Host http.cat
		}
	}
	root * /var/www/eipmain/nh
	respond /seed/* "Gone" 410 {
	close
	}
	import gen
}

http://bhax.nintendohomebrew.com {
	root * /var/www/bhax/web/nbhax
	try_files {path} {path}.html
	encode gzip
}

bfm.nintendohomebrew.com, seedminer.hacks.guide {
	import bfm-header
	root * /var/www/eipmain/nh/seed
	reverse_proxy localhost:8082
	encode gzip
	file_server
	handle_errors {
		rewrite * /{http.error.status_code}
		reverse_proxy https://http.cat {
			header_up Host http.cat
		}
	}
	log {
		level error
		format console
		output file /var/log/bfm_error.log {
			roll_size 25mb
			roll_keep 20
			roll_keep_for 720h
		}
	}
}

http://part1dumper.nintendohomebrew.com https://part1dumper.nintendohomebrew.com {
	reverse_proxy localhost:8081
}

shitpost.lol {
	import header-gen
	root * /var/www/sp
	import gen
}

hacc.me please.hacc.me {
	import header-gen
	root * /var/www/hacc
	import gen
}

friigaemsworld.com {
	import header-gen
	root * /var/www/frigam
	import gen
}

uwu.tax {
	import header-gen
	root * /var/www/uwu
	import gen
}

conversation.id {
	import header-gen
	root * /var/www/conv
	import gen
}

puebes.com {
	import header-gen
	root * /var/www/puebes
	import gen
}

four.family {
    import header-gen
    root * /var/www/four
    import gen
}

230421.wedding {
    import header-gen
    root * /var/www/wedding
    import gen
}

photos.230421.wedding {
	import header-gen
	root * /mnt/wedding/lychee/public
	import gen
}

easymail.sydney {
    import header-gen
    root * /var/www/easymail
    import gen
}

durriesberg.biz {
    import header-gen
    root * /var/www/dberg
    import gen
}

news.eiphax.tech {
    import header-gen
    root * /var/www/news
    import gen
}

blep.co {
    import header-gen
    root * /var/www/blep
    import gen
}

deadletters.club {
    import header-gen
    root * /var/www/deadletters
    import gen
}

photos.four.family {
	import header-gen
	root * /mnt/charlie/public
	import gen
}

photos.moonaglio.wedding photos.agliomoon.wedding moonaglio.wedding agliomoon.wedding {
	import header-gen
	root * /var/www/moonaglio/public
	import gen
}

garden.eiphax.tech {
	import header-gen
	redir https://blog.eiphax.tech/?p=269 permanent
}

3. The problem I’m having:

I would like to use Caddy to output a live readout of system logs such as stderr or journalctl to a designated webpage. I don’t know the best way to go about this and would like some advice.

4. Error messages and/or full log output:

n/a really, just asking for advice

5. What I already tried:

not a problem, seeking advice

6. Links to relevant resources:

1 Like

Maybe something like this:

:80 {
    handle_path /logs/* {
        root * /var/log
        file_server
    }

    ...
}

This will effectively publish /var/log folder of the server under /logs URI prefix of an HTTP endpoint. You can then access your live caddy.log file by http://localhost/logs/caddy.log URL.

Putting such URLs in iframes on a page and issuing refresh commands to them via script timer will provide the illusion of a live readout of the corresponding files.

As a bare minimum, you can just put the list of links to logs on a web page, so the visitors could view each file individually by using their web browsers.

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