Unable to get response from localhost

1. The problem I’m having:

I am trying to get a simple response through my browser.

I had my rpi4 and Caddy running as a NAS about 4 years ago. After a house move I disconnected it and finally just got everything hooked back up. 4 years later I’ve forgotten quite a bit. I was trying to get it running using my previous Caddyfile but was having some issues. I’m sure the issues were due to new router, ip address, using DuckDNS, along with other things. So I went ahead and am now just running a simple Caddyfile with “Hello, World!” and unable to get a web browser to give me a response. I do however get “Hello, World!” printed out by using the curl https://localhost command.

I don’t know if the issue is in my router, security keys, configfile, or else where. I do plan to update both the Debian version and Caddy but first want to just remember how to get this working again.

2. Error messages and/or full log output:

From my web browser…

localhost refused to connect.

3. Caddy version:

v2.4.3

4. How I installed and ran Caddy:

a. System environment:

Raspberry Pi 4
PRETTY_NAME=“Raspbian GNU/Linux 10 (buster)”
NAME=“Raspbian GNU/Linux”
VERSION_ID=“10”
VERSION=“10 (buster)”
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL=“http://www.raspbian.org/
SUPPORT_URL=“RaspbianForums - Raspbian
BUG_REPORT_URL=“RaspbianBugs - Raspbian

b. Command:

sudo caddy start --config /srv/dev-disk-by-label-Ho                                meDrive/HomeDrive/"config files"/Caddy2/Caddyfile
2024/07/13 16:33:33.029 INFO    using provided configuration    {"config_file":                                 "/srv/dev-disk-by-label-HomeDrive/HomeDrive/config files/Caddy2/Caddyfile", "con                                fig_adapter": ""}
2024/07/13 16:33:33.031 WARN    input is not formatted with 'caddy fmt' {"adapte                                r": "caddyfile", "file": "/srv/dev-disk-by-label-HomeDrive/HomeDrive/config file                                s/Caddy2/Caddyfile", "line": 3}
2024/07/13 16:33:33.034 INFO    admin   admin endpoint started  {"address": "tcp                                /localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:                                2019", "localhost:2019"]}
2024/07/13 16:33:33.035 INFO    http    server is listening only on the HTTPS po                                rt but has no TLS connection policies; adding one to enable TLS {"server_name":                                 "srv0", "https_port": 443}
2024/07/13 16:33:33.035 INFO    http    enabling automatic HTTP->HTTPS redirects                                {"server_name": "srv0"}
2024/07/13 16:33:33.035 INFO    tls.cache.maintenance   started background certi                                ficate maintenance      {"cache": "0x362f770"}
2024/07/13 16:33:33.041 INFO    tls     cleaning storage unit   {"description":                                 "FileStorage:/root/.local/share/caddy"}
2024/07/13 16:33:33.047 INFO    tls     finished cleaning storage units
2024/07/13 16:33:33.137 INFO    pki.ca.local    root certificate is already trus                                ted by system   {"path": "storage:pki/authorities/local/root.crt"}
2024/07/13 16:33:33.138 INFO    http    enabling automatic TLS certificate manag                                ement   {"domains": ["localhost"]}
2024/07/13 16:33:33.140 WARN    tls     stapling OCSP   {"error": "no OCSP stapl                                ing for [localhost]: no OCSP server specified in certificate"}
2024/07/13 16:33:33.141 INFO    autosaved config (load with --resume flag)     {                                "file": "/root/.config/caddy/autosave.json"}
2024/07/13 16:33:33.141 INFO    serving initial configuration
Successfully started Caddy (pid=15611) - Caddy is running in the background


c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

localhost

respond "Hello, world!"

5. Links to relevant resources:

Open a web browser on your RPi and try accessing http://localhost or https://localhost . If this works, the issue is likely with your external network configuration.

I’d ensure your firewall, both on the RPi and your router, are allowing incoming HTTP/HTTPS traffic on port 80 and 443.

Not sure how I could access them from my RPi as its controlled through SSH from my computer. I do have dnsmasq, Pihole, OMV, amongst a few other programs on it also. I’ve looked through those conf files to see if there is any mis-information thats changed from my move but it seems fine.

My router does have port 80 and 443 port-forwarded for my RPi’s IP address 192.168.1.29.

Not sure about firewall settings. I did get a new laptop and am using Windows Defender only. I don’t know what I’d need to change there however.

It may not even be a Caddy issue I’m having. I thought I’d start here. I’ll keep looking into other things.

Please upgrade to the latest Caddy version first. We don’t support versions that old. The latest version is v2.8.4.

You shouldn’t use sudo caddy start. You should run Caddy as a systemd service instead. Follow Install — Caddy Documentation to install, and follow the usage instructions here Keep Caddy Running — Caddy Documentation

You can just use curl -v to make requests on your RPi’s terminal to test that Caddy works.

If you use localhost as your site address, then Caddy will only respond if you make a request using localhost as the hostname. If you try that on a different machine, then it won’t connect because localhost means “this same machine”. So curl -v https://localhost from your terminal on your RPi should work, but it will not work from another device.

To test if you can reach it from another machine, you can use :80 to listen only on HTTP to start and connect with http://192.168.1.29 from another machine, and possibly from your phone on cell internet (not wifi) to make sure it can connect from outside.

After that, you can use an actual domain and Caddy will automate issuance of a certificate for it.

3 Likes

Thanks @francislavoie I wasn’t able to get things working again so I am going to just wipe the whole system and rebuild with current versions of everything.

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