1. My Caddy version (caddy version
):
v2.0.0-beta.18 h1:N8CR8nO+n9Sk16CBx6ysVZWIZv0hgtU1J84st1bFWgI=
2. How I run Caddy:
a. System environment:
Ubuntu 18.04 on a public cloud instance from OVH.
b. Command:
I’m not sure what I’m supposed to put here…
c. Service/unit/compose file:
Standard caddy 2 service :
[Unit]
Description=Caddy Web Server
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile --resume --environ
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile --adapter 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:
{
email email@email.com
}
(logs) {
log {
output file /var/log/caddy/access.log
}
}
(yourls) {
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
file_server
encode zstd gzip
import logs
}
liens.macg.io {
root * /var/www/yourls
import yourls
}
liens2.macg.io {
root * /var/www/yourls2
import yourls
}
3. The problem I’m having:
I can’t manage to set up the url shortener service Yourls using Caddy 2.
Using the above configuration, I can access the admin interface fine, but the shorter links are all redirected to the administration rather than to their correct destination.
4. Error messages and/or full log output:
Access logs with the above configuration :
{"level":"info","ts":1584686119.7500317,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/oTJuT","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /oTJuT HTTP/2.0\" 302 0","latency":0.006397828,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Status":["302 Found"],"Location":["https://liens.macg.io/admin"],"Content-Type":["text/html; charset=UTF-8"]}}
{"level":"info","ts":1584686119.7500317,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/oTJuT","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /oTJuT HTTP/2.0\" 302 0","latency":0.006397828,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Status":["302 Found"],"Location":["https://liens.macg.io/admin"],"Content-Type":["text/html; charset=UTF-8"]}}
{"level":"info","ts":1584686119.7500317,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/oTJuT","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /oTJuT HTTP/2.0\" 302 0","latency":0.006397828,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Status":["302 Found"],"Location":["https://liens.macg.io/admin"],"Content-Type":["text/html; charset=UTF-8"]}}
{"level":"info","ts":1584686119.7908714,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin HTTP/2.0\" 308 0","latency":0.000216081,"size":0,"status":308,"resp_headers":{"Server":["Caddy"],"Location":["/admin/"],"Content-Type":[]}}
{"level":"info","ts":1584686119.7908714,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin HTTP/2.0\" 308 0","latency":0.000216081,"size":0,"status":308,"resp_headers":{"Content-Type":[],"Server":["Caddy"],"Location":["/admin/"]}}
{"level":"info","ts":1584686119.7908714,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin HTTP/2.0\" 308 0","latency":0.000216081,"size":0,"status":308,"resp_headers":{"Content-Type":[],"Server":["Caddy"],"Location":["/admin/"]}}
{"level":"info","ts":1584686119.8275764,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin/","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin/ HTTP/2.0\" 200 7267","latency":0.01506835,"size":7267,"status":200,"resp_headers":{"Content-Type":["text/html; charset=utf-8"],"Expires":["Thu, 23 Mar 1972 07:00:00 GMT"],"Last-Modified":["Fri, 20 Mar 2020 06:35:19 GMT"],"Content-Encoding":["gzip"],"Vary":["Accept-Encoding"],"Server":["Caddy"],"Pragma":["no-cache"],"Set-Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; expires=Fri, 27-Mar-2020 06:35:19 GMT; Max-Age=604800; path=/; domain=liens.macg.io; secure; HttpOnly"],"Cache-Control":["no-cache, must-revalidate, max-age=0"]}}
{"level":"info","ts":1584686119.8275764,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin/","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin/ HTTP/2.0\" 200 7267","latency":0.01506835,"size":7267,"status":200,"resp_headers":{"Set-Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; expires=Fri, 27-Mar-2020 06:35:19 GMT; Max-Age=604800; path=/; domain=liens.macg.io; secure; HttpOnly"],"Cache-Control":["no-cache, must-revalidate, max-age=0"],"Last-Modified":["Fri, 20 Mar 2020 06:35:19 GMT"],"Content-Encoding":["gzip"],"Vary":["Accept-Encoding"],"Server":["Caddy"],"Pragma":["no-cache"],"Content-Type":["text/html; charset=utf-8"],"Expires":["Thu, 23 Mar 1972 07:00:00 GMT"]}}
{"level":"info","ts":1584686119.8275764,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/admin/","proto":"HTTP/2.0","remote_addr":"86.253.229.114:53180","host":"liens.macg.io","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"],"Accept-Language":["fr-fr"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; experimentation_subject_id=ImIyZjFmM2Y4LTU3OWItNDg2Yy1hYmU2LTFkZjQzNGMyNTE2MSI%3D--dbd7f97ae060fe4bfe8aa5ca427457726aeb76f4"]},"tls":{"resumed":true,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"liens.macg.io"}},"common_log":"86.253.229.114 - - [20/Mar/2020:07:35:19 +0100] \"GET /admin/ HTTP/2.0\" 200 7267","latency":0.01506835,"size":7267,"status":200,"resp_headers":{"Content-Encoding":["gzip"],"Vary":["Accept-Encoding"],"Server":["Caddy"],"Pragma":["no-cache"],"Content-Type":["text/html; charset=utf-8"],"Expires":["Thu, 23 Mar 1972 07:00:00 GMT"],"Last-Modified":["Fri, 20 Mar 2020 06:35:19 GMT"],"Set-Cookie":["yourls_20e6eb59858c3b25aed1109e5dd21ab1=abd9927d0100164f4263b438fff52fda; expires=Fri, 27-Mar-2020 06:35:19 GMT; Max-Age=604800; path=/; domain=liens.macg.io; secure; HttpOnly"],"Cache-Control":["no-cache, must-revalidate, max-age=0"]}}
5. What I already tried:
Here’s what I had for Caddy 1 :
(yourls) {
log /var/log/caddy/yourls.access.log
errors /var/log/caddy/yourls.error.log
fastcgi / /var/run/php/php7.0-fpm.sock php
rewrite / {
r (.*)
to {uri} {uri}/ /yourls-loader.php?{query}
}
gzip
}
liens.macg.io {
import yourls
root /var/www/yourls
}
liens2.macg.io {
import yourls
root /var/www/yourls2
}
It worked perfectly then.
I tried to reproduce the rewrite from Caddy 1 which worked fine. Since it’s not possible to just reproduce it on Caddy 2, I guess I don’t know how to do this.
Here’s what I tried first :
(yourls) {
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
file_server
encode zstd gzip
import logs
try_files {path} {path}/ /yourls-loader.php?{query}&p={path}
}
Now, the links are correctly expanded, but the admin is inaccessible. It loops itself on a series of redirects and the admin is never displayed.
So I added this :
(yourls) {
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
file_server
encode zstd gzip
import logs
rewrite /admin/* /index.php?{query}&p={path}
try_files {path} {path}/ /yourls-loader.php?{query}&p={path}
}
It was the same result.
6. Links to relevant resources:
Here’s the official recommended nginx configuration for Yourls : Nginx configuration · YOURLS/YOURLS Wiki · GitHub
Thanks for your help !