Cant see my webpage on localhost

1. Output of caddy version:

v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy:

a. System environment:

Windows 11

b. Command:

caddy run 

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane. -->

d. My complete Caddy config:

localhost {
	respond "hello"
}

localhost:2020 {
	root * "c:/=x=/root/www/"
	file_server
}

192.168.102.216 {
	respond "hello 2"
}

192.168.102.216:2020 {
	root * c:/=x=/root/www/
	file_server
}

3. The problem I’m having:

C:\Users\Me>curl -v 192.168.102.216

  • Trying 192.168.102.216:80…
  • Connected to 192.168.102.216 (192.168.102.216) port 80 (#0)

GET / HTTP/1.1
Host: 192.168.102.216
User-Agent: curl/7.83.1
Accept: /

  • Mark bundle as not supporting multiuse
    < HTTP/1.1 308 Permanent Redirect
    < Connection: close
    < Location: https://192.168.102.216/
    < Server: Caddy
    < Date: Mon, 05 Sep 2022 19:18:41 GMT
    < Content-Length: 0
    <
  • Closing connection 0

C:\Users\Me>curl -v 192.168.102.216:2020

  • Trying 192.168.102.216:2020…
  • Connected to 192.168.102.216 (192.168.102.216) port 2020 (#0)

GET / HTTP/1.1
Host: 192.168.102.216:2020
User-Agent: curl/7.83.1
Accept: /

  • Mark bundle as not supporting multiuse
  • HTTP 1.0, assume close after body
    < HTTP/1.0 400 Bad Request
    <
    Client sent an HTTP request to an HTTPS server.
  • Closing connection 0

4. Error messages and/or full log output:

Paste logs/commands/output here.
USE THE PREVIEW PANE TO MAKE SURE IT LOOKS NICELY FORMATTED.

5. What I already tried:

I have a caddyfile in the the same folder (www) as the index.html

When I write “localhost” in the adressbar, I see “hello”. So it works so far.

But when I write “localhost:2020” to see may homepage (@ c:/=x=/root/www/index.html) I see nothing, just a blank screen.

My question are:

What Im a doing wrong, why cant I see my webpage (c:/=x=/root/www/index.html) when I try to open “localhost:2020”?

6. Links to relevant resources:

This request is triggering a redirect from port 80 to port 443, because Caddy is HTTPS by default.

If you try curl -v https://192.168.102.216 you might get further. But you might get TLS errors because Caddy won’t be able to issue a TLS certificate for an IP address hostname as per Automatic HTTPS — Caddy Documentation so you’d need to add tls internal to your config for that to work… plus you’d need to install the internal CA’s root certificate to any devices you might make requests from.

Similarly here, you didn’t specify https://, so curl tried an HTTP request, but that server is listening for HTTPS requests.

If you’re fine with just HTTP in your local network, you can prefix your site address with http://. No problems if you trust the devices on your network.

1 Like

(One minor correction: Caddy will still issue self-signed TLS certificates in this case. Caddy uses HTTPS for everything except port 80 or explicit HTTP or when TLS is explicitly disabled.)

When I test curl with https:// it looks like this.

C:\Users\Me>curl -v https://192.168.102.216
*   Trying 192.168.102.216:443...
* Connected to 192.168.102.216 (192.168.102.216) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: using IP address, SNI is not supported by OS.
* ALPN: offers http/1.1
* schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
* Closing connection 0
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

C:\Users\Me>curl -v https://192.168.102.216:2020
*   Trying 192.168.102.216:2020...
* Connected to 192.168.102.216 (192.168.102.216) port 2020 (#0)
* schannel: disabled automatic use of client certificate
* schannel: using IP address, SNI is not supported by OS.
* ALPN: offers http/1.1
* schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
* Closing connection 0
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

But I dont get it, I dont see “hello” or “hello 2” when I curl but when I test “localhost” and “https://192.168.102.216” in the webbrowser I get “hello” or “hello 2” that part works at least there.

But https://192.168.102.168:2020 I get nothing just:

# This 192.168.102.216 page can’t be found
No webpage was found for the web address: **https://192.168.102.216:2020/**
HTTP ERROR 404

And for localhost:2020 in the webbrowser I get

# Hmmm… can't reach this page
The connection was reset.

Shouldn’t they get the same error message? localhost:2020 is the same as https://198.168.102.216:2020.

I tried to add “tls internal” but it did not make any difference.

First time caddy started it asked to add cert “Caddy Local Authority - ECC Intermediate”. Edge use windows CA store but Firefox use its own. So edge I get “hello” but in Firefox I first get a warning.

SEC_ERROR_UNKNOWN_ISSUER

But when I proced and click on the button “accept the risk” I get “hello” in firefox to and I can see the cert is:

Common Name: Caddy Local Authority - ECC Intermediate
DNS Name: localhost

So there is a cert from caddy in some way.

No, they are different! :slight_smile: localhost is a hostname, and 198.168.102.216 is an IP address (that’s not even on the loopback interface). The difference matters when it comes to TLS (that’s not a Caddy thing).

Caddy isn’t able to install itself into every root store (yet) – we use a dependency that I hope will eventually be able to support more stores.