Reverse proxy 404

1. The problem I’m having:

reverse proxy results in 404.
caddy reverse-proxy -f http://localhost:3001 -t https://al-mostafa.info --insecure --debug

2. Error messages and/or full log output:

2024/01/13 04:18:20.300 WARN  admin admin endpoint disabled
2024/01/13 04:18:20.302 INFO  tls.cache.maintenance started background certificate maintenance  {"cache": "0x1400059c380"}
2024/01/13 04:18:20.302 WARN  http.auto_https automatic HTTPS is completely disabled for server {"server_name": "proxy"}
2024/01/13 04:18:20.302 DEBUG http.auto_https adjusted config {"tls": {"automation":{"policies":[{}]}}, "http": {"servers":{"proxy":{"listen":[":3001"],"routes":[{"handle":[{"handler":"reverse_proxy","transport":{"protocol":"http","tls":{"insecure_skip_verify":true}},"upstreams":[{"dial":"al-mostafa.info:443"}]}]}],"automatic_https":{"disable":true}}}}}
2024/01/13 04:18:20.304 DEBUG http  starting server loop  {"address": "[::]:3001", "tls": false, "http3": false}
2024/01/13 04:18:20.304 INFO  http.log  server running  {"name": "proxy", "protocols": ["h1", "h2", "h3"]}
Caddy proxying http://localhost:3001 -> al-mostafa.info:443
2024/01/13 04:18:20.317 INFO  tls finished cleaning storage units
2024/01/13 04:19:07.141 DEBUG http.handlers.reverse_proxy selected upstream {"dial": "al-mostafa.info:443", "total_upstreams": 1}
2024/01/13 04:19:07.530 DEBUG http.handlers.reverse_proxy upstream roundtrip  {"upstream": "al-mostafa.info:443", "duration": 0.388923916, "request": {"remote_ip": "127.0.0.1", "remote_port": "53720", "client_ip": "127.0.0.1", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3001", "uri": "/data/arabic/depot/gap.php?file=001051-www.al-mostafa.com.pdf", "headers": {"Sec-Fetch-Site": ["none"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0"], "X-Forwarded-Proto": ["http"], "Sec-Fetch-Mode": ["navigate"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Fetch-User": ["?1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"], "Accept-Language": ["en-US,en;q=0.5"], "X-Forwarded-For": ["127.0.0.1"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "X-Forwarded-Host": ["localhost:3001"]}}, "headers": {"Server": ["nginx"], "Content-Type": ["text/html"], "Connection": ["keep-alive"], "Accept-Ranges": ["bytes"], "Content-Encoding": ["gzip"], "X-Powered-By": ["PleskLin"], "Date": ["Sat, 13 Jan 2024 04:19:07 GMT"], "Content-Length": ["598"], "Last-Modified": ["Sun, 27 Mar 2016 03:26:15 GMT"], "Etag": ["\"e5967-400-52eff5bd70ba6\""], "Vary": ["Accept-Encoding"]}, "status": 404}
2024/01/13 04:19:07.568 DEBUG http.handlers.reverse_proxy selected upstream {"dial": "al-mostafa.info:443", "total_upstreams": 1}
2024/01/13 04:19:07.568 DEBUG http.handlers.reverse_proxy upstream roundtrip  {"upstream": "al-mostafa.info:443", "duration": 0.0003, "request": {"remote_ip": "127.0.0.1", "remote_port": "53720", "client_ip": "127.0.0.1", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3001", "uri": "/favicon.ico", "headers": {"Sec-Fetch-Site": ["same-origin"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0"], "Accept": ["image/avif,image/webp,*/*"], "Accept-Language": ["en-US,en;q=0.5"], "X-Forwarded-For": ["127.0.0.1"], "Referer": ["http://localhost:3001/data/arabic/depot/gap.php?file=001051-www.al-mostafa.com.pdf"], "X-Forwarded-Proto": ["http"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Fetch-Mode": ["no-cors"], "X-Forwarded-Host": ["localhost:3001"], "Sec-Fetch-Dest": ["image"]}}, "error": "context canceled"}

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

brew install caddy

a. System environment:

macbook m3, running caddy directly in terminal

b. Command:

caddy reverse-proxy -f http://localhost:3001 -t https://al-mostafa.info --insecure --debug

c. Service/unit/compose file:

n/a

d. My complete Caddy config:

n/a

You probably need to also set --change-host-header otherwise the upstream sees localhost as the Host header.

1 Like

Thanks @francislavoie, that was it!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.