giopas
(giopas)
May 22, 2022, 1:36pm
1
1. Caddy version (caddy version
):
2.5.0
2. How I run Caddy:
caddy run --config /share/home/test.conf -agree -email test@gmail.com -root /home/Qhttpd -log /share/home/caddy2.log -pidfile /var/run/caddy.pid &
a. System environment:
QNAP
b. config file
xx.iiiiii.xyz {
log / /share/home/xx.log
reverse_proxy http://192.168.10.7:4040
}
3. The problem I’m having:
What Caddy v.1 I was using the command line mentioned under [2] above (except config, of course). But now I receive the error:
flag provided but not defined: -agree.
Usage of run: (…)
What I am missing, how should I pass the -agree, -email, -log and other settings in the string?
Thanks!
Caddy v2 is a complete rewrite from Caddy v1. The CLI has significantly changed. See the docs, all those options other than --config
do not exist anymore.
Make sure to name your config file Caddyfile
, not test.conf
.
See the upgrade guide:
giopas
(giopas)
May 22, 2022, 10:17pm
3
Thank you. I am trying to learn more and I have modified the lunch script as follows:
./caddy run --config /share/home/caddy/caddy2-conf -->watch --pidfile /var/run/caddy.pid &
The config file is the following:
{
log {
output file /share/home/caddy/caddy2.log
}
email test@gmail.com
}
eg.example.xyz {
log / /share/home/caddy/example.log
reverse_proxy http://192.168.10.7:4040
}
However if I run a test, I get:
./caddy validate --config >/share/home/caddy/caddy2-conf
2022/05/22 22:13:05.018 INFO using provided >configuration {“config_file”: >“/share/home/admin/caddy/caddy2-conf”, >“config_adapter”: “”}
validate: decoding config: invalid character ‘l’ looking >for beginning of object key string
What am I missing?
Like I said, name your config Caddyfile
.
Caddy’s underlying config is JSON. The caddyfile is an adapter that transforms a Caddyfile config into JSON.
Also, your log
directive inside your site block is not correct. Review the docs for the log
directive.
Also, don’t use &
when running Caddy to put it in the background. Instead, you should run Caddy as a systemd service.
If you install Caddy with one of the methods on the Install — Caddy Documentation page, it should already be set up for you to run as a systemd service.
But it seems like QNAP does their own weird stuff so you don’t have systemd: Running Your Own Application at Startup - QNAPedia
giopas
(giopas)
May 23, 2022, 5:49am
5
Ok, thanks.
Now in my sh lunch script, I have:
./caddy run --config /share/home/caddy/Caddyfile -->watch --pidfile /var/run/caddy.pid &
The config file has been renamed as Caddyfile and it is like the following:
{
log {
output file /share/home/caddy/caddy2.log
}
email example@gmail.com
}
eg.example.com {
reverse_proxy http://192.168.10.7:4040
}
http://xyz.example.com {
reverse_proxy http://192.168.10.7:8000
}
Now it seems working!
I just need to learn:
how to put logs back (they are used for goaccess),
how to use the following reverse proxy argument (as it was under v.1): http://192.168.10.7:5678/directory
how to use authentication for a single site (that should be easy)
how to use gzip. Under version 1, I had the following part in the general section. Can I use the below?
gzip {
ext *
level 7
min_length 1
}
Thanks again for guiding me through it!
giopas:
how to put logs back (they are used for goaccess),
Just use the log
directive.
Make sure to update your goaccess config to use Caddy’s JSON format.
giopas:
Do the rewrite beforehand, with the rewrite
directive.
giopas:
how to use authentication for a single site (that should be easy)
Depends on the kind of auth you need. Did you read the docs?
You’re looking for the encode
directive. No need to configure gzip level/length, just use encode gzip
.
1 Like
giopas
(giopas)
May 23, 2022, 2:02pm
7
Thank you!
I did some more digging, and - beside the fact that I still need to look into goaccess config to be sure I can use Caddy’s JSON format - this is new configfile I am building (which I cannot test now as I am outside the LAN):
{
log {
output file /share/home/caddy/caddy2.log
}
email example@gmail.com
encode gzip
header Strict-Transport-Security max-age=31536000;
}
eg.example.com {
log {
outputfile /share/home/caddy/example.log
}
reverse_proxy http://192.168.10.7:4040
}
http://xyz.example.com {
rewrite http://192.168.10.7:8000 http://192.168.10.7:8000/directory
reverse_proxy http://192.168.10.7:8000
}
http://abc.example.com {
basicauth {
Bob JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX
}
reverse_proxy http://192.168.10.7:8000
}
Is the gzip, log, rewrite, header and basicauth syntax correct?
Of course for the latter, I understand that I need to use caddy hash-password
.
Thanks!
Rewrites only work on the request path and query, not the whole URL. This is incorrect.
These are site directives, not global options. They aren’t valid here. You need to put them in each site.
You missed a space between output
and file
here.
Also, please run caddy fmt --overwrite Caddyfile
to clean up your config’s syntax.
giopas
(giopas)
May 23, 2022, 4:09pm
9
Thanks!
Does it mean that I have to use something like the following?
rewrite * /directory
To preserve the original URL, you’d need to do this:
rewrite * /directory{uri}
giopas
(giopas)
May 23, 2022, 7:31pm
11
thank you, all done! After a couple of years (or more) I finally moved to Caddy2
1 Like
system
(system)
Closed
June 21, 2022, 1:37pm
12
This topic was automatically closed after 30 days. New replies are no longer allowed.