Hey,
since caddy is now almost stable, I wanted to give it a shot. Sadly I felt a little disappointed since many of the old directives were missing. Additionally, I caused a "caddy panic" after 5 minutes:
./caddy run --config="/opt/caddy/caddyfile" --adapter="caddyfile"
2020/04/03 15:11:52.942 INFO using provided configuration {"config_file": "/opt/caddy/caddyfile", "config_adapter": "caddyfile"}
2020/04/03 15:11:52.945 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["localhost:2019"]}
2020/04/03 15:11:52.946 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv1"}
2020/04/03 15:11:52.946 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv2"}
2020/04/03 15:11:52.946 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv3"}
2020/04/03 15:11:52.946 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv0"}
2020/04/03 15:11:52 [INFO][cache:0xc000171130] Started certificate maintenance routine
2020/04/03 15:11:52.947 INFO http enabling automatic TLS certificate management {"domains": ["test.com", "test2.mail"]}
2020/04/03 15:11:52.959 INFO tls cleaned up storage units
2020/04/03 15:11:52.960 INFO autosaved config {"file": "/root/.config/caddy/autosave.json"}
2020/04/03 15:11:52.960 INFO serving initial configuration
2020/04/03 15:12:01 http2: panic serving [removed]XXX.XXX.XXX.XXX[removed]:47228: runtime error: slice bounds out of range [:-1]
goroutine 84 [running]:
net/http.(*http2serverConn).runHandler.func1(0xc0001351e8, 0xc000a0bf8e, 0xc000683e00)
net/http/h2_bundle.go:5713 +0x16b
panic(0x14d07c0, 0xc000775b20)
runtime/panic.go:967 +0x166
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.buildEnv(0x15dac9c, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00047ac60, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:190 +0x1931
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.RoundTrip(0x15dac9c, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00047ac60, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:96 +0x90
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).reverseProxy(0xc0004717c0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc000171950, 0x159aa05, 0x3, 0xc0007da8e0, 0xe, 0xc000716060, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:441 +0x1ec
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).ServeHTTP(0xc0004717c0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x18882c0, 0x1679040, 0x0, 0x0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:346 +0xc76
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0x1885220, 0xc0004717c0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:256 +0x5f
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007798f0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc0008ab201, 0xea1878)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0x0, 0xc00041dfc0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:231 +0x121
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000a02140, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x0, 0x0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0x1, 0x1)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:203 +0x2ec
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000a02160, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x1679040, 0x18882c0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc00041dd40, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x18882c0, 0x1679040, 0x1458b80, 0xea1901)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/subroute.go:74 +0x8a
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0x1884f40, 0xc00041dd40)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:256 +0x5f
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007798c0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc0008ab401, 0xea1878)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0x0, 0xc0002e3560)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:231 +0x121
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149a0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x0, 0x1)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc000387638, 0x40c786)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:203 +0x2ec
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149c0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x7, 0x2)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler(0xc0002df320, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0x18882c0, 0xc0007149c0, 0xc0008ab700, 0x7d5cbe)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:273 +0x9b
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).wrapPrimaryRoute.func1(0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc000779890, 0xc000820720)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:249 +0x5a
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149e0, 0x18a1460, 0xc0001351e8, 0xc000a00200, 0xc000820700, 0xc000a00100)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0002df320, 0x18a1460, 0xc0001351e8, 0xc000a00200)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:204 +0x85d
net/http.serverHandler.ServeHTTP(0xc0007ac380, 0x18a1460, 0xc0001351e8, 0xc000a00000)
net/http/server.go:2807 +0xa3
net/http.initALPNRequest.ServeHTTP(0x18a6520, 0xc00076c510, 0xc0004ae000, 0xc0007ac380, 0x18a1460, 0xc0001351e8, 0xc000a00000)
net/http/server.go:3381 +0x8d
net/http.(*http2serverConn).runHandler(0xc000683e00, 0xc0001351e8, 0xc000a00000, 0xc0007bff00)
net/http/h2_bundle.go:5720 +0x8b
created by net/http.(*http2serverConn).processHeaders
net/http/h2_bundle.go:5454 +0x4e1
2020/04/03 15:12:01 http2: panic serving [removed]XXX.XXX.XXX.XXX[removed]:47228: runtime error: slice bounds out of range [:-1]
goroutine 30 [running]:
net/http.(*http2serverConn).runHandler.func1(0xc000914050, 0xc000a0bf8e, 0xc000683e00)
net/http/h2_bundle.go:5713 +0x16b
panic(0x14d07c0, 0xc000775bc0)
runtime/panic.go:967 +0x166
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.buildEnv(0x15dac9c, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00047ac60, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:190 +0x1931
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.RoundTrip(0x15dac9c, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00047ac60, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:96 +0x90
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).reverseProxy(0xc0004717c0, 0x18a1460, 0xc000914050, 0xc000a00400, 0xc000171950, 0x159aa05, 0x3, 0xc0007da960, 0xe, 0xc000716060, ...)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:441 +0x1ec
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).ServeHTTP(0xc0004717c0, 0x18a1460, 0xc000914050, 0xc000a00400, 0x18882c0, 0x1679040, 0x0, 0x0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:346 +0xc76
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0x1885220, 0xc0004717c0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:256 +0x5f
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000779b60, 0x18a1460, 0xc000914050, 0xc000a00400, 0xc0008ab201, 0xea1878)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0x0, 0xc00041dfc0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:231 +0x121
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000a02400, 0x18a1460, 0xc000914050, 0xc000a00400, 0x0, 0x0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0x1, 0x1)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:203 +0x2ec
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000a02420, 0x18a1460, 0xc000914050, 0xc000a00400, 0x1679040, 0x18882c0)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc00041dd40, 0x18a1460, 0xc000914050, 0xc000a00400, 0x18882c0, 0x1679040, 0x1458b80, 0xea1901)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/subroute.go:74 +0x8a
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0x1884f40, 0xc00041dd40)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:256 +0x5f
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc000779b30, 0x18a1460, 0xc000914050, 0xc000a00400, 0xc0008ab401, 0xea1878)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0x0, 0xc0002e3560)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:231 +0x121
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149a0, 0x18a1460, 0xc000914050, 0xc000a00400, 0x0, 0x1)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1(0x18a1460, 0xc000914050, 0xc000a00400, 0xc000387638, 0x40c786)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:203 +0x2ec
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149c0, 0x18a1460, 0xc000914050, 0xc000a00400, 0x7, 0x2)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler(0xc0002df320, 0x18a1460, 0xc000914050, 0xc000a00400, 0x18882c0, 0xc0007149c0, 0xc0008ab700, 0x7d5cbe)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:273 +0x9b
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).wrapPrimaryRoute.func1(0x18a1460, 0xc000914050, 0xc000a00400, 0xc000779b00, 0xc000820780)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:249 +0x5a
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0007149e0, 0x18a1460, 0xc000914050, 0xc000a00400, 0xc000820700, 0xc000a00300)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/caddyhttp.go:61 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0002df320, 0x18a1460, 0xc000914050, 0xc000a00400)
github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/server.go:204 +0x85d
net/http.serverHandler.ServeHTTP(0xc0007ac380, 0x18a1460, 0xc000914050, 0xc000815500)
net/http/server.go:2807 +0xa3
net/http.initALPNRequest.ServeHTTP(0x18a6520, 0xc00076c510, 0xc0004ae000, 0xc0007ac380, 0x18a1460, 0xc000914050, 0xc000815500)
net/http/server.go:3381 +0x8d
net/http.(*http2serverConn).runHandler(0xc000683e00, 0xc000914050, 0xc000815500, 0xc0004aab00)
net/http/h2_bundle.go:5720 +0x8b
created by net/http.(*http2serverConn).processHeaders
net/http/h2_bundle.go:5454 +0x4e1
2020/04/03 15:12:04.414 INFO shutting down {"signal": "SIGINT"}
2020/04/03 15:12:04 [INFO][cache:0xc000171130] Stopped certificate maintenance routine
2020/04/03 15:12:04.414 INFO shutdown done {"signal": "SIGINT"}
In the end I had to kill it.
The used caddyfile is:
test.com {
# push
# cache
reverse_proxy / 127.0.0.1:1091 {
transport fastcgi
}
header / {
Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
includeSubdomains
}
# ipfilter / {
# rule allow
# database /opt/caddy/GeoLite2-Country.mmdb
# country US
# }
tls {
# key_type rsa2048
protocols tls1.2 tls1.3
}
}
I had to comment out all the stuff which has missing directives or modules since caddy1.
The panic appeared, when the transport fastcgi was added.
--> btw. is there an alternative to the proxy { transparent } from caddy1? I always thought it is very handy.
e.g.
proxy / web1.local:80 web2.local:90 web3.local:100 {
policy round_robin
health_check /health
transparent
}
Thanks for opening an issue! We'll look into this.
It's not immediately clear to me what is going on, so I'll need your help to understand it better.
Ideally, we need to be able to reproduce the bug _in the most minimal way possible_. This allows us to write regression tests to verify the fix is working. If we can't reproduce it, then you'll have to test our changes for us until it's fixed -- and then we can't add test cases, either.
I've attached a template below that will help make this easier and faster! It will ask for some information you've already provided; that's OK, just fill it out the best you can. :+1:
I've also included some helpful tips below the template. Feel free to let me know if you have any questions!
Thank you again for your report, we look forward to resolving it!
## 1. Environment
### 1a. Operating system and version
paste here
1b. Caddy version (run caddy version or paste commit SHA)
paste here
1c. Go version (if building Caddy from source; run go version)
paste here
2. Description
2a. What happens (briefly explain what is wrong)
2b. Why it's a bug (if it's not obvious)
2c. Log output
paste terminal output or logs here
2d. Workaround(s)
2e. Relevant links
3. Tutorial (minimal steps to reproduce the bug)
Environment: Please fill out your OS and Caddy versions, even if you don't think they are relevant. (They are _always_ relevant.) If you built Caddy from source, provide the commit SHA and specify your exact Go version.
Description: Describe at a high level what the bug is. What happens? Why is it a bug? Not all bugs are obvious, so convince readers that it's actually a bug.
Tutorial: What are the _minimum required specific steps_ someone needs to take in order to experience the same bug? Your goal here is to make sure that anyone else can have the same experience with the bug as you do. You are writing a tutorial, so make sure to carry it out yourself before posting it. Please:
curl.Example of a tutorial:
Create a config file:Open terminal and run Caddy:{ ... }Make an HTTP request:$ caddy ...Notice that the result is ___ but it should be ___.$ curl ...
Also, this seems like the panic should only happen if .php isn't in the request. (It's even a TODO in the current code.) Can you fill out the above template (see the helpful tips) and let me know how to reproduce the bug?
--> btw. is there an alternative to the proxy { transparent } from caddy1? I always thought it is very handy.
Caddy 2 passes the headers thru by default, including the Host header, and adds X-Forwarded-For, so you don't need transparent in v2.
See this guide for more info: https://caddyserver.com/docs/v2-upgrade#proxy
Wait a sec...
Are you using PHP or just FastCGI without PHP?
If you're using PHP, you want the php_fastcgi directive instead of reverse_proxy, see here: https://caddyserver.com/docs/v2-upgrade#fastcgi
This is still a bug, but before I can fix it I need to know what you're trying to do and how to reproduce it.
# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.7.1908 (Core)
Release: 7.7.1908
Codename: Core
caddy version or paste commit SHA)caddy_2.0.0-rc.1_Linux_x86_64
I tried Caddy2 the first time. --> Changed the existing caddy1 caddyfile into a runnable version for caddy2 and caused therefore a panic.
It's a panic. I guess that should be catched before it happens (or be prevented).
please have a look at the first post. :)
I tested it again to tell the steps for reproduction.
reverse_proxy / 127.0.0.1:1091 {
transport fastcgi
}
-->
Caddy 2 passes the headers thru by default, including the Host header, and adds X-Forwarded-For, so you don't need transparent in v2.
Sadly I can't proxy any of my (right now through caddy1 served) websites through caddy2. I guess cookies aren't passed through properly. I guess I just have to learn how to handle the new caddy. Otherwise... when '"including the Host header, and adds X-Forwarded-For"' it should just work fine, right?
Thanks for the added info.
Here comes my mistake. I didn't check properly which of my backends is listening on Port 1091.
What do you mean by this?
Apparently it isn't using PHP. As soon you try to load this Page through caddy2 (while the wrong transport is chosen) it causes a "caddy panic".
I see, so your backend is a FastCGI responder but is not using PHP. So a request, for example, would have an empty path such as /, right?
Sadly I can't proxy any of my (right now through caddy1 served) websites through caddy2. I guess cookies aren't passed through properly.
Well, the fastcgi transport works different from the HTTP transport. Both send all the headers, but in the fastcgi case it creates an env variable called HTTP_HEADER_NAME like HTTP_COOKIE and that's how fastcgi backends get the cookie information.
What was your working v1 config?
@Pamalosebi I've pushed a fix in 1e8af27 - please try it out! There will be build artifacts you can download momentarily.
Thank you a lot!
I've pushed a fix in 1e8af27 - please try it out! There will be build artifacts you can download momentarily.
I surely will. Probably this is not the correct place for further questions. --> But I may write my question here: https://caddy.community/
Build artifacts: https://github.com/caddyserver/caddy/actions/runs/70010904
As noted in https://caddy.community/t/caddy-v2-and-caddyfile-just-serves-plain-sites/7424/5, confirmed to be fixed :+1:
Most helpful comment
As noted in https://caddy.community/t/caddy-v2-and-caddyfile-just-serves-plain-sites/7424/5, confirmed to be fixed :+1: