caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.83k stars 3.98k forks source link

Reverse proxy internal port redirection #1400

Closed high3eam closed 7 years ago

high3eam commented 7 years ago

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

Caddy 0.9.5 (+dc6c986 Fr Feb 03 17:01:32 UTC 2017)

2. What are you trying to do?

I use caddy as a reverse proxy, that runs in transparent mode and pipelines requests to my nginx (which serves as the backend. the app "myapp" is in the html directory which has the rightpermissions set to it.

3. What is your entire Caddyfile?

https://myapp.henrock.net {

        tls /etc/caddy/ssl/my.crt /etc/caddy/ssl/my.key {

                protocols       tls1.0 tls1.2
                curves          p521 p384 p256

        }
################################
## Tried this (v) to not get redirected to internal port, but didn't work.. 
################################
#       redir 307 {
#           https://{host}{uri}     https://{host}
#       }

    proxy / localhost:8073 { #http requests get proxied to this internal port.
        transparent
        header_upstream X-Frame-Options SAMEORIGIN
        }

    proxy / localhost:8083 { #https requests get proxied to this internal port.
        transparent
                header_upstream X-Frame-Options SAMEORIGIN
        }

        gzip {

                ext *
                level 4

        }

        header / {

                X-XSS-Protection "1; mode=block"
                X-Content-Type-Options "nosniff"
                X-Frame-Options "SAMEORIGIN"
                Strict-Transport-Security "max-age=15768000; includeSubdomains; preload;"
                Server "henrock-caddy"

        }

        errors {

                log /etc/caddy/log/error.log
                404 /etc/caddy/errdoc/404.html # Not Found
                500 /etc/caddy/errdoc/500.html # Internal Server Error

        }

                root /etc/caddy/html/myapp.henrock.net
                ext .html .htm .php
                log /etc/caddy/log/access.log
}

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

ulimit -n 8192 && screen ./caddy -conf /etc/caddy/caddy.cf -cpu 2 -log stdout -quic

5. What did you expect to see?

MyApp redirects from the index.php in folder: https://myapp.henrock.net to https://myapp.henrock.net/login.php

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

I get redirected to: https://myapp.henrock.net:8073/login.php

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

Hard to explain, because either the reproduction gets really hard for someone starting from scratch (since I compiled the current newest version of nginx and the config is also very long), or different versions are colliding. I really think, this might just be a little configuration issue on the caddy site itself.

mholt commented 7 years ago

What's the redirect code? If it's not a temporary redirect maybe it's cached in the browser from an old configuration? I haven't seen this problem except perhaps through misconfigured upstreams...

mholt commented 7 years ago

Also, what if you disable quic? This'll have to be reduced to a minimal case to replicate the issue. Until then, I'll close this, because it's hard to verify that it's a bug in Caddy with all the extra stuff going on. Also you have two proxy directives that operate on the same path, which is a little confusing. I'm not sure it's doing what you think it's configured to do. It'll have to choose one of those backends but they both match to the same requests...