Caddy serve an ip address

1. The problem I’m having:

I’m trying to add a second website to be hosted by Caddy. It doesn’t matter if it’s by https or http.

The second website doesn’t have a domain, so I was hoping Caddy could serve the index.html at the ip address for the server.

The other website hosted by Caddy still works when I try to add the second website. It’s only the new website that doesn’t show in the browser.

I tried to add the second website by doing this in my caddyfile

94.130.26.101:80 {
   root * /var/www/html2
   file_server
}

2. Error messages and/or full log output:

When I enter the ip address in the browser it says `This site can’t provide a secure connection`

3. Caddy version:

v2.7.6

4. How I installed and ran Caddy:

a. System environment:

Ubuntu

b. Command:

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

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:

{
  debug

  servers {
        metrics
  }
}
cabincrewforyou.com {
        # Set this path to your site's directory.
        root * /var/www/html

        # Enable the static file server.
        file_server

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}
94.130.26.101:80 {
   root * /var/www/html2
   file_server
}

5. Links to relevant resources:

Probably because you tried using https:// instead of http://.

Why aren’t you using a domain? You can use a subdomain of your existing domain, like foo.cabincrewforyou.com or whatever.

I’m not using a domain because I don’t want to show the domain (the only one I have) to a potential client. I’d rather it be an ip address rather than the stupid domain name.

So you expect Caddy to be able to serve an ip address like this?

94.130.26.101:80 {
   root * /var/www/html2
   file_server
}

You can get more domains, e.g. free ones from DuckDNS or whatever. You’re not limited to only having one domain.

There’s no issue with serving from an IP host. You haven’t actually shown the evidence that it’s not working. Make a request with curl -v and show what you get.

I assumed i’d be able to reach the website through the IP address in the browser, and when I couldn’t, assumed that something was wrong with my Caddyfile.

When I curl my website curl https://cabincrewforyou.com, I get the index page for var/www/html, so I’d hope to see the index page for var/www/html2when I do curl 94.130.26.101:80 or curl http://94.130.26.101 but I get nothing.

When I do curl -v 94.130.26.101, I get

* Trying 94.130.26.101...

* TCP_NODELAY set

* Connected to 94.130.26.101 (94.130.26.101) port 80 (#0)

> GET / HTTP/1.1

> Host: 94.130.26.101

> User-Agent: curl/7.64.1

> Accept: */*

>

< HTTP/1.1 308 Permanent Redirect

< Connection: close

< Location: https://94.130.26.101/

< Server: Caddy

< Date: Wed, 20 Mar 2024 17:31:14 GMT

< Content-Length: 0

<

* Closing connection 0

Is that what you’d expect to see? I have no idea if it’s “working”.

Are you sure you reloaded Caddy after changing your config?

That behaviour from curl -v shows that Caddy responded with a redirect to HTTPS after seeing your request, which is the default behaviour when there’s no site.

Show your Caddy logs, please.

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