Caddy: Proxying to another Caddy service serving files doesn't work (beta 0.9)

Created on 9 Jun 2016  路  13Comments  路  Source: caddyserver/caddy

_Thanks for such an awesome tool!_ I might have found a small bug in the beta version....

1. What version of Caddy are you running (caddy -version)?

Caddy 0.9-beta.1 AND Caddy downloaded via get (master) April 23rd on Computer 1
Caddy downloaded via get (master) April 23rd on Computer 2

2. What are you trying to do?

Computer 1 detects address https://myaddress.com and forwards to internal address on Computer 2 (192.168.1.11:8061) which is hosting files via a Caddy service.

3. What is your entire Caddyfile?

Caddyfile for Computer 1:

myaddress.com {
        gzip
        basicauth / user password
        proxy / 192.168.1.11:8061
}

Caddyfile for Computer 2:

192.168.1.11:8061 {
        gzip
        root /media/d
        browse /
}

4. How did you run Caddy (give the full command and describe the execution environment)?

If I use the old version (downloaded from master branch on April 23) for Computer 1 and Computer 2 I run

$GOPATH/bin/caddy on Computer 1, and $GOPATH/bin/caddy on Computer 2.

Currently I'm trying the beta version (0.9 beta 1) on Computer 1 (installed to /usr/local/bin) so I run

/usr/local/bin/caddy on Computer 1, and $GOPATH/bin/caddy on Computer 2.

5. What did you expect to see?

There is no problem using the old versions of Caddy (downloaded from master branch April23). Computer 1 detects the address, and correctly forwards to port to the Caddy service on Computer 2 which shows the files.

6. What did you see instead (give full error messages and/or log)?

There is a problem using the 0.9 beta 1 version on Computer 1 (which forwards the port). The browser simply says "No such host at :8061". It is no longer forwarding to the Caddy service on Computer 2. The problem still exists even if Computer 2 had a new version of Caddy.

The problem seems to be with forwarding since I can still access Computer 2 at 192.168.1.11:8061 directly (locally), with no problem.

If I use a different service to host files on Computer 2 (e.g. python3 -m http.server 8061) then the 0.9 beta version of Caddy on computer 1 works fine. So it seems it just doesn't like forwarding to another Caddy service?

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

Try install a new Caddy version on two computers. Try forwarding ports from an address on the first Computer to a Caddy service on the second computer hosting files using an internal address+port.

bug

Most helpful comment

I got it to work with proxy_header Host 192.168.1.11

All 13 comments

Hi @schollz, thanks for your comments and the report! I think I'm seeing the same behavior, but have yet to understand it. Will need to look at this some more.

Hi, I'm surprised that old versions work.

Trying adding this proxy_header and see if the behaviour changes.

myaddress.com {
        gzip
        basicauth / user password
        proxy / 192.168.1.11:8061 {
            proxy_header Host {host}
        }
}

I got it to work with proxy_header Host 192.168.1.11

Thanks @abiosoft, that did the trick!
Works for me now too.

Interesting, I did not get it to work with proxy_header Host {host} since that should set the Host field to myaddress.com instead of 192.168.1.11 which is what the backend expects.

@abiosoft Do you know if this behavior is new/different than before? I can't recall. And I haven't written tests for this yet :sweat_smile:

So both

myaddress.com {
        gzip
        basicauth / user password
        proxy / 192.168.1.11:8061 {
                proxy_header Host {host}
        }
}

and

myaddress.com {
        gzip
        basicauth / user password
        proxy / 192.168.1.11:8061 {
                proxy_header Host 192.168.1.11
        }
}

seem to work for me. Should I actually use the IP address though, since Computer 2 doesn't look for myaddress.com?

The first one should not work, I'm surprised that it does for you; it did not for me!

Is this new behavior with 0.9 beta only? If both caddy instances are running 0.8.3 did it work previously?

When I use 0.8.3 on both instances, each of the following works:

        proxy / 192.168.1.11:8061 {
                proxy_header Host 192.168.1.11
        }

or

        proxy / 192.168.1.11:8061 {
                proxy_header Host {host}
        }

or

        proxy / 192.168.1.11:8061

Its only the last one that doesn't work in 0.9 beta.

Hmm, I will try to understand this better to be sure this change, if it is a change, was intended; and perhaps get some tests behind it.

@schollz If you can run Caddy from source, I've pushed those couple commits to master that may possibly resolve your issue. Could you check? I'm also grateful to have @evermax's help to debug this.

I'm pretty convinced we got the behavior we were aiming for, so I'm going to close this now. You can verify at will. Thanks!

Hi @mholt,

Cool! I can confirm that it works for me now using master source on both computers, using my original Caddyfiles (as in 3 in my original post)!

Thanks for your vigilance, great work on Caddy - keep it up!

That's great @schollz - thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whs picture whs  路  3Comments

lorddaedra picture lorddaedra  路  3Comments

jgsqware picture jgsqware  路  3Comments

SteffenDE picture SteffenDE  路  3Comments

muhammadmuzzammil1998 picture muhammadmuzzammil1998  路  3Comments