How to change a service implementation to use a caddyfile?

1. Caddy version (caddy version):

2.4.6

2. How I run Caddy:

I’m running it as a service as recommended by the link below fo rManagerIO

a. System environment:

I have a proliant DL180G6 running Truenas V12.0-U6. I have VM’s setup with Ubuntu 18.04.5. One VM has only one purpose in life and that is to host the accounting application named ManagerIO.

b. Command:

This link is what I implemented to setup the application and Caddy service - see the link for ManagerIO below

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

The recommended configuration does not use a caddyfile however I would like to.

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

3. The problem I’m having:

ManagerIO lets me put image files in their database but they instead recommend keeping image files on a separate server so the database isn’t bloated up.

Their recommended setup for Caddy works great but it does not let me also setup a local file-server to serve image files (maybe it will but I don’t find any documentation on how to put multiple directives in the command line call) I am trying to have the caddy.service use a Caddyfile to startup - so I can: first reverse-proxy without the embedded CLI parameter; then expand the Caddyfile to enable a local caddy file server to serve image files.

4. Error messages and/or full log output:

systemctl status caddy displays … Active: failed (Result: exit-code …) and code=exited, status=1

5. What I already tried:

I have read through the Caddy documentation and tried to implement Caddy as recommeded, ie: create a clean VM with Ubuntu, install Caddy per the install docs at caddyserver.com for debian-ubuntu-raspbian.

I’ve been logged in as root for all of these actions.

Once that’s done I install ManagerIO, but not their section on “Setting up HTTPS”, then I modified the Caddyfile to reverse proxy for the managerio application. I’m not trying to do anything else - just to get HTTPS for ManagerIO to work with a Caddyfile as it now works with their recommended service setup. I have tried the approaches recommended in the tutorials on the caddyserver site using a single reverse_proxy command in the Caddyfile.

When I use systemctl start caddy to start the service I receive the report and error above.

I hope not to waste anyone’s time however I have invested over 40 hours time to learn about Caddy and to follow through the tutorials to get familiar with how it works. I had been using Let’s Encrypt before I implemented ManagerIO’s solution “Setting up HTTPS” so I’m really happy with how easy Caddy is and I’d like to continue using Caddy with ManagerIO. There are a lot of ManagerIO users who have problems using images in their databases so a Caddy solution to support ManagerIO and a local image server would be sweet!

Thank You for any help you can send our way!

6. Links to relevant resources:

https://www.manager.io/server/installation/ubuntu/

With Caddy installed using the apt repo, Caddy is already set up to run as a systemd service with a Caddyfile. Your Caddyfile is in /etc/caddy/Caddyfile.

Please read this page in the docs to understand how the Caddyfile is structured.

You will be able to construct a Caddyfile that handles both the reverse proxy and static file configuration.

Its important to review the documentation that Francis pointed out, but realize the configuration is possible with something like this
(no I didn’t caddy fmt this, I just winged it, sorry to the readers)

https://[your IP or host FQDN] {
        route /images/* {
                uri strip_prefix /images
                file_server {
                        root /var/www/
                }
        }
       route /* {
             reverse_proxy http://localhost:8080
       }
}

Also I would not use the approach ManagerIO gives to create the systemctl file from that URL you gave… (wow :roll_eyes:)
Instead follow this documentation:
Keep Caddy Running — Caddy Documentation.

Let us know what you come up with after reviewing docs and testing with the example. (I’m not understanding the images thing fully that you need to set up)

There might also be TLS (HTTPS) setup considerations depending on if you are internet facing using FQDN (letsencrypt will be default), local IP address (simple, caddy forces local) or attempting to use internal DNS FQDN’s (some considerations in what you lay out in your caddyfile there).

1 Like

WOW! You guys are fast and on a weekend too! Thank You!

I have not yet experimented with agrajag’s suggestion, except for confirmation to abandon the ManagerIO suggested approach. I did double check what I had done against advice from francislavoie and honestly, I had already reviewed the documentation many many times so his advice had already been applied - BUT - after more mucking about and being somewhat desperate, I went off script and discovered this worked…

(no site address)

first.site.block {
reverse_proxy server.address.here.and:port
}

second.site.block {
reverse_proxy server.address.here.and:port
}

I hadn’t tried this earlier as I was following the advice for wildcard site handling, but could never get it to work. As expected, all reverse_proxies give me https connections. I don’t know if it’s not recommend but it’s working.

I have now been able to setup my configuration as I imagined I might:
internet → caddy server → reverse_proxies to separate servers running whatever software without concern for secure connections or limits in scalability!

Thank You Again for your fast help!

1 Like

Thank you again for your fast help!

I now realize the approach I’m using is not actually “off-script” but clearly stated in the documentation. If it was a snake it would have bit me!

Caddy seems to stop working, even though it is running, and a Reload or a start-stop does not get it working again, only a system bounce, so I’m thinking it’s my Ubuntu 18.04.5 instance.

Where should I go to see what tools Caddy offers to help me diagnose my problem?

Best Regards,

Lee

I don’t understand what problem you’re encountering. Please post your logs, curl -v requests, etc.