1. Output of caddy version
:
v2.5.1 h1:bAWwslD1jNeCzDa+jDCNwb8M3UJ2tPa8UZFFzPVmGKs=
2. How I run Caddy:
a. System environment:
Mac OS X
b. Command:
caddy run --watch
c. Service/unit/compose file:
N/A
d. My complete Caddy config:
localhost:2015 {
handle /proxy/i {
reverse_proxy {query.url}
}
}
3. The problem I’m having:
I’m trying to get a URL from a query parameter ( /proxy/i?url=www.example.com/someimage.png )
The issue is that on reverse_proxy, the extra path would cause an invalid dial address : missing port in address since there is a path (someimage.png).
e.g.
https://localhost:2015/proxy/i?url=https%3A%2F%2Fstatic.ktbyte.cn%2Fimages%2Fscifi.jpg
would do reverse_proxy directly to the image
https://static.ktbyte.cn/images/scifi.jpg
However I believe it has to be reverse_proxy https://static.ktbyte.cn
and I’d have to then pass /images/scifi.jpg
through a rewrite
or uri
. I’m not sure, what the right approach is.
4. Error messages and/or full log output:
2022/08/11 22:39:12.226 ERROR http.log.error making dial info: upstream {query.url.hostname}: invalid dial address : missing port in address {"request": {"remote_ip": "::1", "remote_port": "51668", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:2015", "uri": "/proxy/i?url=https%3A%2F%2Fstatic.ktbyte.cn%2Fimages%2Fscifi.jpg", "headers": {"Accept-Language": ["en-CA,en;q=0.9,ru-KZ;q=0.8,ru;q=0.7,en-GB;q=0.6,en-US;q=0.5,fr;q=0.4"], "Cookie": [], "Sec-Fetch-Dest": ["document"], "Cache-Control": ["no-cache"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Sec-Ch-Ua-Platform": ["\"macOS\""], "Sec-Fetch-Site": ["none"], "Sec-Ch-Ua-Mobile": ["?0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"], "Accept-Encoding": ["gzip, deflate, br"], "Pragma": ["no-cache"], "Sec-Ch-Ua": ["\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\""]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "localhost"}}, "duration": 0.00008913, "status": 502, "err_id": "rs74xf208", "err_trace": "reverseproxy.statusError (reverseproxy.go:1196)"}
5. What I already tried:
I tried the above and considered a double reverse_proxy to extract the relevant information.