-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caddyfile log directive not working when header_up Host set #3509
Comments
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! This will require some effort on your part -- please understand that we will be dedicating time to fix the bug you are reporting if you can just help us understand it and reproduce it easily. This template will ask for some information you've already provided; that's OK, just fill it out the best you can. 👍 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! Template
Helpful tips
Example of a tutorial: Create a config file: |
The logger is determined here, using the request Host: caddy/modules/caddyhttp/server.go Lines 172 to 175 in 3af15c0
When setting header_up Host for the reverse proxy, it must be overriding the original request's Host header, which causes the named logger to not be found and accLog to be used instead. caddy/modules/caddyhttp/server.go Lines 447 to 453 in 3af15c0
As a result, these requests end up getting logged by the default "logger":"http.log.access" instead of the appropriate "logger":"http.log.access.logX" A temporary workaround would be to deploy another site to act as the intermediary. Here we can set header_up Host since we won't be enabling logging. The docs don't mention being able to set variables using Caddyfile, so I've set duplicate headers for x-forwarded-for and x-forwarded-proto to use in the reverse_proxy (since otherwise they'll be set again). Note: the original x-forwarded headers become replaced inside the reverse_proxy block (much like host) which is why alternate headers need to be set first. As well, it appears the shorthand
This way, the original request host is maintained for localhost/bad/ and the named logger can be found and used accordingly. The fix should occur in the reverseproxy section, ensuring that original request headers (specifically Host) are not overridden by header_up ones. |
Thanks for the good instructions, but I'm not able to reproduce the problem. I used your Caddyfile verbatim, and this is my output log file:
Using these commands:
(To clarify, the reverse proxy doesn't (shouldn't) override the original |
Ah, it looks like caddy doesn't treat Updated Caddyfile:
Now it gets interesting. In the case of
As well, other hosts seem to still match this block (in the case of http). These requests also get logged to the main http.log.access: (note: this is not the original issue but is potentially related)
edit: also, have updated caddy since first post: |
The actual domain names are very important, so that's why we ask that users don't redact, alter, or change their configs (except credentials) when posting them. This morning was my scheduled time on this issue; I'll have another chance to look at this next time, probably in a week or two. Someone else can look at it before then if they want (or you can!). |
Thanks for the info -- as I said, the hostnames do matter so that's why we ask people to never change them when they post reports or ask for help. Finally had some time to look at this again and I think you're right as to the cause, so that made things a bit easier. |
caddy 2.0.0 on ubuntu focal (20.04 lts)
demo Caddyfile:
In this example, requests to
domain.com/good/
will log to/var/log/caddy/access.log
as expected. However,domain.com/bad/
requests are not and are instead default logged:journalctl -f -u caddy
caddy[215]: {"level":"info","ts":1592615674.2224905,"logger":"http.log.access","msg":"handled request",...
edit 20200706: changed from
localhost
todomain.com
The text was updated successfully, but these errors were encountered: