Reverse proxy with domain name

1. Caddy version:

v2.6.4 on Ubuntu

2. How I installed, and run Caddy:

Using the script within the help Caddy documentation. Direct installation within the OS. The linux server is not doing anything else and will only be a reverse proxy.

a. System environment:

Ubuntu 22 (Ubuntu 22.04.2 LTS)

b. Command:

THIS WORKS:
caddy reverse-proxy --from :2015 --to http://192.168.0.157:80

THIS DOES NOT WORK:
caddy reverse-proxy --from http://gci.localhost:2015 --to http://192.168.0.157:80

c. Service/unit/compose file:

n/a

d. My complete Caddy config:

not using a caddy file

3. The problem I’m having:

I am trying to get a reverse proxy to work.

I have two servers:
192.168.0.157 - simple apache server which will server a webpage on http port 80
192.168.0.167 - caddy which I want to be a reverse proxy and redirect traffic based or servername

When I run the command ‘caddy reverse-proxy --from :2015 --to http://192.168.0.157:80’ it will work fine. When accessing http://192.168.0.167:2015 I get the webpage from http://192.168.0.157:80

I have changed my hosts.ini to direct all traffic from gci.localhost to 192.168.0.167. A ping confirms this.

The caddy command ‘caddy reverse-proxy --from gci.localhost --to http://192.168.0.157:80’ does not work. I have tried various combinations and cannot get http://gci.localhost to work and show me the webpage from http://192.168.0.157:80

4. Error messages and/or full log output:

root@caddy:/# caddy reverse-proxy --from http://gci.localhost:2015 --to http://192.168.0.157:80
2023/02/23 09:09:20.849 WARN admin admin endpoint disabled
2023/02/23 09:09:20.850 WARN http automatic HTTPS is completely disabled for server {“server_name”: “proxy”}
2023/02/23 09:09:20.852 INFO http.log server running {“name”: “proxy”, “protocols”: [“h1”, “h2”, “h3”]}
Caddy proxying http://gci.localhost:2015 → 192.168.0.157:80
2023/02/23 09:09:20.853 INFO tls cleaning storage unit {“description”: “FileStorage:/root/.local/share/caddy”}
2023/02/23 09:09:20.854 INFO tls finished cleaning storage units
2023/02/23 09:09:20.855 INFO tls.cache.maintenance started background certificate maintenance {“cache”: “0xc0000d8f50”}

5. What I already tried:

I have tried all manner of combinations. I cannot get a hostname to ever be proxied by caddy.

6. Links to relevant resources:

That’s normal behaviour. If you configure --from with a domain, then Caddy will only respond to requests with that hostname.

That doesn’t work. Many clients always resolve *.localhost to 127.0.0.1 ignoring all DNS/hosts config. It doesn’t make sense to use a non-localhost IP address for a localhost domain.

Perfect!!!

That was exacly the problem. I needed to use a dummy .com domain.

1 Like

The more “correct” TLD to use is *.home.arpa FWIW. Using *.test is fine too.

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