Beginner having trouble setting up a reverse proxy

1. Output of caddy version:

2.6.1

2. How I run Caddy:

I have Caddy installed on a Privileged Ubuntu container in my Proxmox server

a. System environment:

Ubuntu 20.04 priveledged container

b. Command:

sudo caddy start

d. My complete Caddy config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

books2.jveronese.com {
        # Set this path to your site's directory.
        # root * /usr/share/caddy

        # Enable the static file server.
        # file_server

        # Another common task is to set up a reverse proxy:
        reverse_proxy 192.168.1.68:80
        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

3. The problem I’m having:

I have a few servers currently running on my homelab that I’d like to access without going through Cloudflare’s Zero Trust Tunnels for HTTPS. This is my current setup, but I get the error “too many redirects” when trying to access this via my web browser.

4. Error messages and/or full log output:

Output from “journalctl -u caddy --no-pager | less +G” gives me a bunch of lines with “~” followed by

-- Logs begin at Wed 2022-09-28 15:26:21 UTC, end at Wed 2022-09-28 15:26:30 UTC. --
-- No entries --

Tyring to use “curl -v” asks for a URL. Should I be using it on my domain or on the servers IP address?

This is what I get when trying it through the full URL on a different network. If that isn’t right please let me know.

C:\Users\jveronese>curl books2.jveronese.com -v
*   Trying xx.xx.xx.xx:80...
* Connected to books2.jveronese.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: books2.jveronese.com
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://books2.jveronese.com/
< Server: Caddy
< Date: Wed, 28 Sep 2022 18:35:53 GMT
< Content-Length: 0
<
* Closing connection 0

5. What I already tried:

Including ports, including http://, trying a separate reverse proxy for my Nextcloud server already over HTTPS (which gives a different error)

We need to see your logs regardless.

See the docs for how to look at your logs when running as a systemd service:

Also, try making a request with curl -v, and show us what you see.

Apologies, what I should have posted was that “journalctl -u caddy --no-pager | less +G” gives me a bunch of lines with “~” followed by

-- Logs begin at Wed 2022-09-28 15:26:21 UTC, end at Wed 2022-09-28 15:26:30 UTC. --
-- No entries --

Tyring to use “curl -v” asks for a URL. Should I be using it on my domain or on the servers IP address?

This is what I get when trying it through the full URL on a different network. If that isn’t right please let me know.

C:\Users\jveronese>curl books2.jveronese.com -v
*   Trying xx.xx.xx.xx:80...
* Connected to books2.jveronese.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: books2.jveronese.com
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://books2.jveronese.com/
< Server: Caddy
< Date: Wed, 28 Sep 2022 18:35:53 GMT
< Content-Length: 0
<
* Closing connection 0

Is Caddy even running as a systemd service then? It seems like it’s not, if you’re not even seeing Caddy’s startup logs.

This is giving expected behaviour, i.e. a redirect from HTTP to HTTPS (with the Location header) because you didn’t specify the scheme, so curl assumes HTTP.

Instead, run this:

curl -v https://books2.jveronese.com

Actually, I think what’s happening is you’re telling Caddy to proxy to itself. So you get a redirect loop of HTTP->HTTPS redirects.

Make sure you have the right IP and port for your upstream app.

1 Like

I have seen this on fresh VPS (virtual private server) wherein journalctl does not report any logs despite the systemd unit writing them. Usually a reboot fixes it. However, this begs the question whether you’re running Caddy using systemd or just running it directly in your shell.

1 Like

This fixed it. I’ve been staring at this for too long lol. This does lead me to a second issue though. I also have NextCloud running (with it’s own SSL from Let’s Encrypt). However, it resolves to an error that says

Bad Request
Your browser sent a request that this server could not understand.
You're speaking plain HTTP to an SSL-enabled server port. Instead use HTTPS scheme to access this URL.

Is there somthing I need to enable in my config to let the HTTPS talk to it? Or should I just disable HTTPS on NextCloud? Would Caddy take care of the HTTPS portion on its own?

My Caddy file

nimbus.jveronese.com {
        reverse_proxy 192.168.1.226:443
}
1 Like

It seems to be running. If I look at systemctl it shows green and active. Even after a reboot the logs still show the same thing.

1 Like

Yes, that’s what Caddy excels at. Caddy’s most famous feature is Automatic HTTPS.

See this article, which explains how the networking works when you’re running Caddy in a home network:

Got it, with SSL disabled on the Cloudflare end everything works and it looks like Caddy is giving me the green lock, so I think we’re all good.

Thanks!

2 Likes

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