Redir not working

1. The problem I’m having:

I’m using caddy to reverse_proxy to a nuxt app, but when trying to add some 301 redirects on the caddyfile in order to redirect some old url paths into a new location, the redirect is not happening.

2. Error messages and/or full log output:

No error message, Caddy just ignores the redirect and sends the request with the old url to nuxt, which in turn gives a 404 error (route not found)

3. Caddy version:

Caddy 2.7.6

4. How I installed and ran Caddy:

brew install caddy

a. System environment:

MacOS v14.2.1 Sonoma

b. Command:

sudo caddy run

c. Service/unit/compose file:

n/a

d. My complete Caddy config:

:443

redir /en/some-old-url.html /new-url permanent

@cachedFiles {
        path *.jpg *.jpeg *.png *.gif *.webp *.ico *.js *.css
}
header @cachedFiles Cache-Control "public, max-age=604800, must-revalidate"

encode gzip zstd

reverse_proxy localhost:3000

5. Links to relevant resources:

n/a

Show an example request with curl -v. Are you sure the request path actually matches? Show some evidence.

Hey sorry I forgot to add the curl output, here it is:

% curl -v https://localhost/en/some-old-url.html
*   Trying [::1]:443...
* Connected to localhost (::1) port 443
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: [NONE]
*  start date: Mar  7 03:00:54 2024 GMT
*  expire date: Mar  7 15:00:54 2024 GMT
*  subjectAltName: host "localhost" matched cert's "localhost"
*  issuer: CN=Caddy Local Authority - ECC Intermediate
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://localhost/en/some-old-url.html
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: localhost]
* [HTTP/2] [1] [:path: /en/some-old-url.html]
* [HTTP/2] [1] [user-agent: curl/8.4.0]
* [HTTP/2] [1] [accept: */*]
> GET /en/some-old-url.html HTTP/2
> Host: localhost
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/2 404
< alt-svc: h3=":443"; ma=2592000
< content-type: application/json
< date: Thu, 07 Mar 2024 09:13:27 GMT
< server: Caddy
< vary: Accept-Encoding
< content-length: 205
<
* Connection #0 to host localhost left intact
{"url":"/en/some-old-url.html","statusCode":404,"statusMessage":"Page not found: /en/some-old-url.html","message":"Page not found: /en/some-old-url.html","stack":"","data":{"path":"/en/some-old-url.html"}}%

Ok,

Sorry about this post, it was actually a PEBKAC issue :sweat_smile:

For some reason I had another caddy process running in the background that was using a default configuration apparently.

After disabling it and running with the correct Caddyfile it still wouldn’t work until i changed the first line from :443 to localhost:443 (without the localhost part it was apparently assuming the servername)

Either way, the (not a) problem is now gone and redirect is working correctly.

Sorry again for taking some of your time but thanks anyway! :+1:

1 Like

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