Help migrating from v.1 to v. 2

Hi all,

after years not touching anything, I said that with your help I could finally jump on v2!

1. Caddy version (caddy version):

Version 1

2. How I run Caddy:

qpkg installed and runs on QNAP at start.

Ports 443 and 80 are forwarded by the router to the server.

Everything works fine under v. 1, but I think it would be best practice and more secure to migrate everything to v. 2.

Honestly, I do not need all the log function if it could create problems.

a. System environment:


b. Command:


QPKG_ROOT=`/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}`
APACHE_ROOT=`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/`

export QPKG_ROOT
export QPKG_NAME

export SHELL=/bin/sh
export LC_ALL=en_US.UTF-8
export USER=admin
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8

export CADDYPATH=/share/homes/user/caddy/Caddypath

ulimit -n 8192

export PIDF=/var/run/

case "$1" in
    ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
    if [ "$ENABLED" != "TRUE" ]; then
        echo "$QPKG_NAME is disabled."
        exit 1
/bin/ln -sf $QPKG_ROOT /opt/$QPKG_NAME
/bin/ln -sf $QPKG_ROOT/caddy /usr/bin/caddy

caddy -conf /share/homes/user/caddy/caddy.conf -agree -email -root /home/Qhttpd -log /share/homes/user/caddy/caddy.log -pidfile /var/run/ &



ID=$(more /var/run/

        if [ -e $PIDF ]; then
            kill -9 $ID
            rm -f $PIDF

rm -rf /opt/$QPKG_NAME
rm -rf /usr/bin/caddy


    $0 stop
    $0 start

    echo "Usage: $0 {start|stop|restart}"
    exit 1

exit 0

d. My complete Caddyfile or JSON config:


(gzipconf) {
	gzip {
		ext *
		level 7
		min_length 1

(addheader) {
	header / {
		Strict-Transport-Security "max-age=31536000;"
		X-XSS-Protection "1; mode=block"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "SAMEORIGIN"
		Referrer-Policy "strict-origin-when-cross-origin"

### server NAS {
	import gzipconf
	import addheader
	log / /share/homes/user/caddy/accesslogs/server-NAS.log "{hostonly} {combined} {latency_ms}"
	proxy / {
		keepalive 32

3. The problem I’m having:

Help moving to version 2 (for the config file, as the sh would be upgraded by the new qpkg, and I think it would need simple customization.

4. Error messages and/or full log output:

Not tried yet as really afraid to break 20 and counting proxies…

5. What I already tried:

Reading the doc[1], but I am really bad at understanding JSON and necessary steps.

[1] Upgrading to Caddy 2 — Caddy Documentation

6. Links to relevant resources:

Hmm, well I have no experience with QNAP, so I’m not sure I can help with that part.

We have a systemd service file you can find here, if it uses systemd :man_shrugging:

Well, give a shot at converting the Caddyfile to Caddy v2 format, and if you run into snags, we can help.

You don’t need to JSON at all. In Caddy v2, the Caddyfile is an adapter which outputs JSON config, which Caddy actually runs with. But that’s just an implementation detail most of the time.

What JSON are you trying to understand exactly? There’s no JSON on that page :thinking:

Ok, so there is no straight forward way to convert the code below?

That would be already a good start for me…

From the guide should it be something like the following? {

But I have no idea how would be the entire section…

Yep, just reverse_proxy

Caddy v2’s proxy has “transparent” and “websocket” enabled by default, essentially. And you likely don’t need to modify keepalives, rarely any benefit to do so. The defaults are sufficient.

Thank you, so the whole file could be reduced to: {


And if I want to put back logging, can I use exactly the same syntax? {
log / /share/homes/user/caddy/accesslogs/server-NAS.log "{hostonly} {combined} {latency_ms}" 


For logging, please see the upgrade guide, and v2 docs: Upgrading to Caddy 2 — Caddy Documentation

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