Hosting firefly (nginx convert)

1. Caddy version (caddy version):

v2.2.0

2. How I run Caddy:

a. System environment:

Ubuntu Server 18.04 TLS

b. Command:

caddy run

c. Service/unit/compose file:

# 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

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

kraenshomeserver.duckdns.org {
        root * /var/www/kraenshomeserver.duckdns.org/html
        file_server
}

kraenshomeserver.duckdns.org/firefly {
        root * /var/www/kraenshomeserver.duckdns.org/firefly-iii/public

        log {
                output file /var/log/caddy/firefly.log
                level ERROR
        }

        file_server

        encode gzip

        php_fastcgi unix//run/php/php7.4-fpm.sock

        try_files {path} {path}/ /index.php?{query}

        #rewrite /{path}/* ?{query}

}

3. The problem I’m having:

First of all - no logging. Don’t know what’s wrong. File should be writable but nothing shows.

Second - when accessing my subfolder firefly - nothing shows. I’ve tried just using a respond and that works fine.

I’ve included the recommended nginx setup from their docs. Can anyone help?

location ^~ /firefly-iii/ {
   deny all;
}
​
location ^~ /budget {
   alias /var/www/firefly-iii/public;
   try_files $uri $uri/ @budget;
​
   location ~* \.php(?:$|/) {
      include snippets/fastcgi-php.conf;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
   }
}
​
location @budget {
   rewrite ^/budget/(.*)$ /budget/index.php/$1 last;
}

4. Error messages and/or full log output:

Nothing. See first problem above.

5. What I already tried:

I’ve tried looking for solutions, but there aren’t that many running Firefly on Caddy. I found following code for v1, but I can’t seem to modify it to work on v2

firefly.yourdomain.org {

	root /usr/local/www/firefly-iii/public
	log /var/log/firefly_access.log
	errors /var/log/firefly_errors.log

	tls {
		ca https://acme-staging-v02.api.letsencrypt.org/directory
	}

	gzip
	fastcgi / 127.0.0.1:9000 php

	rewrite {
		to {path} {path}/ /index.php?{1}
	}

}

6. Links to relevant resources:

https://docs.firefly-iii.org/faq/self_hosted
https://forum.freenas-community.org/t/firefly-iii-personal-finance-manager-in-a-jail/45

I think this is closer to what you want:

kraenshomeserver.duckdns.org {
	log {
		output file /var/log/caddy/kraenshomeserver.log
		level ERROR
	}

	handle_path /firefly* {
		root * /var/www/kraenshomeserver.duckdns.org/firefly-iii/public
		encode gzip
		php_fastcgi unix//run/php/php7.4-fpm.sock
		file_server
	}

	handle {
		root * /var/www/kraenshomeserver.duckdns.org/html
		file_server
	}
}

A few things to note:

  • Path matching is exact-match in Caddy v2, so matching on /firefly will only match exactly /firefly but not /firefly/foo.
  • Access logging can only be enabled for an entire hostname, not for specific paths, so enabling log within a path matched subroute will still enable it for the whole hostname regardless.
  • When Caddy looks for files on disk, it appends the request path to the root path. That means Caddy would be looking for files in /var/www/kraenshomeserver.duckdns.org/firefly-iii/public/firefly, which doesn’t seem right for you. To fix this, the handle_path directive is used, which is the same as handle plus stripping the /firefly prefix from the path before continuing.
  • try_files logic is already built-in to php_fastcgi, so it’s not necessary to add here.
1 Like

Thanks. Logging works so now I can see an error.

{
  "request": {
"remote_addr": "192.168.100.1:64201",
"proto": "HTTP/2.0",
"method": "GET",
"host": "kraenshomeserver.duckdns.org",
"uri": "/firefly/",
"headers": {
  "User-Agent": [
    "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"
  ],
  "Accept": [
    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  ],
  "Accept-Language": [
    "en-US,en;q=0.5"
  ],
  "Accept-Encoding": [
    "gzip, deflate, br"
  ],
  "Dnt": [
    "1"
  ],
  "Cookie": [
    "google2fa_token=eyJpdiI6ImRwSURId1lWcksyUUtmV3FPNkFTbWc9PSIsInZhbHVlIjoiSjdJNTBPKzZwKzVzT29qdXlYOG01Zz09IiwibWFjIjoiMDIxZjYwN2NlYzNjN2U3ZTBjZTVhM2JmOTNmNmM0NzI0ZjI4NDhmZDg3YzQ4YzUyNzU1YjA5MzFjZmViNjk3MSJ9; report-type=category; report-accounts=88; report-categories=25%2C10%2C13%2C4%2C2%2C12%2C18%2C27%2C1%2C21%2C24%2C7%2C17%2C6%2C19%2C26%2C9%2C20%2C23; report-budgets=undefined; report-tags=undefined; report-double=undefined; report-start=20200601; report-end=20200630; remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IjIxdmk0VEw4VHl4c3NpNkgxNThJRmc9PSIsInZhbHVlIjoiWHVSbjJoT3VSSDBEb2tZaW5zbDQ2akwyT3crUzFVTXZJY1lUdVFYSVVLdWhPK2VJdm1oZnlDbUIwZmhZNEdHaElRR0kralV6TVpCeDdcL2ZjQlF6RkUyNFVKUHdrZER1bEJ0dE1CeDhFZVQ2bnZ2bk01cm14WVRtZlwvMTlrRnpobThcL0Q3VzNTbXJCNDQ1SWJoSm9oKzhvVm9iMU41MEs2SklBWDZOWVRuTEJNPSIsIm1hYyI6IjFkY2E0M2MzNDI3OGY3MjhhOWEzMmQ5M2VmMTFlMzE1MzljZDhhYmNjY2YwZTNhMDg3ZDI2MmI2MjcxNDZkMDUifQ%3D%3D"
  ],
  "Upgrade-Insecure-Requests": [
    "1"
  ],
  "Te": [
    "trailers"
  ]
},
"tls": {
  "resumed": false,
  "version": 772,
  "cipher_suite": 4865,
  "proto": "h2",
  "proto_mutual": true,
  "server_name": "kraenshomeserver.duckdns.org"
}
  },
  "common_log": "192.168.100.1 - - [01/Oct/2020:07:07:45 +0000] \"GET /firefly/ HTTP/2.0\" 500 0",
  "duration": 0.005429066,
  "size": 0,
  "status": 500,
  "resp_headers": {
"Server": [
  "Caddy"
],
"Status": [
  "500 Internal Server Error"
],
"Content-Type": [
  "text/html; charset=UTF-8"
]
  }
}

That error is coming from firefly. You’ll need to dig deeper in that app to figure out what’s going wrong. It’s not a problem with Caddy specifically at this point.

Does firefly configure any error logging?

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