Can't access served pages remotely

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

as a service

a. System environment:

Ubunto 18.04

b. Command:

n/a

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

{

  # This is pointing to Let's Encrypt Staging environment (for dev)
  # https://letsencrypt.org/docs/staging-environment/
  # This will allow you to get things right before issuing trusted
  # certificates and reduce the chance of your running up against rate limits.
  # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
  
  # causes all certificates to be issued internally by default,
  # rather than through a (public) ACME CA such as Let's Encrypt.
  # This is useful in development environments.
  local_certs
  
  # configure automatic HTTPS. It can either disable it entirely (off)
  # or disable only HTTP-to-HTTPS redirects (disable_redirects).
  auto_https off

  debug
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

(SecurityHeaders) {
  header_up X-Real-IP {remote_host}
  header_up X-Forwarded-Proto {scheme}
}

localhost:80 {
  # serve photography folder
  root /files/* /opt/ivt/photography
  
  # Set this path to your site's directory.
  root * /opt/ivt/apps/6.0.0/packages/client/spa

  # Enable the static file server.
  file_server

  route /weather/* {
    uri replace /weather /socket.io
    reverse_proxy * http://localhost:3010 {
      import SecurityHeaders
    }
  }
  route /ptz/* {
    uri replace /ptz /socket.io
    reverse_proxy * http://localhost:3006 {
      import SecurityHeaders
    }
  }
  route /liveview/* {
    uri replace /liveview /socket.io
    reverse_proxy * http://localhost:3004 {
      import SecurityHeaders
    }
  }
  route /archive/* {
    uri replace /archive /socket.io
    reverse_proxy * http://localhost:3003 {
      import SecurityHeaders
    }
  }
  route /alarms/* {
    uri replace /alarms /socket.io
    reverse_proxy * http://localhost:3002 {
      import SecurityHeaders
    }
  }
  route /console_socket/* {
    uri replace /console_socket /console/socket.io
    reverse_proxy * http://localhost:3001 {
      import SecurityHeaders
    }
  }
  route /web_app_socket/* {
    uri replace /web_app_socket /web/socket.io
    reverse_proxy * http://localhost:3001 {
      import SecurityHeaders
    }
  }
  route /* {
    reverse_proxy * http://localhost:3001 {
      import SecurityHeaders
    }
  }
}

3. The problem I’m having:

I can open a browser on the same computer as Caddy is running and input localhost and it works fine.

If I go to a second computer and input the IP address of the computer with Caddy, I get nothing.

4. Error messages and/or full log output:

From secondary computer:

$ curl -i -X GET http://192.168.0.14/api/v1/about
HTTP/1.1 200 OK
Server: Caddy
Date: ...
Content-Length: 0

no journal entry is made. :frowning: I am not sure why there is no journal entry for this.

But, from localhost:

$ curl -i -X GET http://localhost/api/v1/about
HTTP/1.1 200 OK
Content-Length: 135
Content-Type: application/json; charset=utf-8
Date: Thu, 17 Sep 2020 19:37:58 GMT
Etag: W/"87-eTJV9Ee6bV/3pw/Kep+x7959pqY"
Server: Caddy
Vary: Accept-Encoding

{"payload":{"about":{"id":1,"release":"Alpha","sc_uuid":"6735f346-f2f7-4dde-aa59-8779e4b7e4c7","version":"6.0.0","revision":"0.4631"}}}

and journal entry:

Sep 17 13:33:25 FLEX-5 caddy[19133]: {"level":"debug","ts":1600371205.4501693,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"localhost:3001","request":{"method":"GET","uri":"/api/v1/about","proto":"HTTP/1.1","remote_addr":"127.0.0.1:40110","host":"localhost","headers":{"X-Forwarded-Proto":["http"],"X-Real-Ip":["127.0.0.1"],"X-Forwarded-For":["127.0.0.1"],"User-Agent":["curl/7.58.0"],"Accept":["*/*"]}},"duration":0.014104832,"headers":{"Etag":["W/\"87-eTJV9Ee6bV/3pw/Kep+x7959pqY\""],"Vary":["Accept-Encoding"],"Date":["Thu, 17 Sep 2020 19:33:25 GMT"],"Connection":["keep-alive"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["135"]},"status":200}

Or, I can use the specific port and by-pass caddy from the remote computer:

$ curl -i -X GET http://192.168.0.14:3001/api/v1/about

and this works similar to being on the local machine and using localhost

5. What I already tried:

I am sure it is something incorrect with my Caddyfile. Quite frankly, I have looked at it a dozen times and nothing is jumping out at me, so I defer to those more knowledgeable. Thanks for your help.

However, by being able to by-pass Caddy and still get the data means, to me, that something is wrong with my Caddyfile.

6. Links to relevant resources:

That’s because Caddy is only accepting requests to localhost. Just change this to :80 and you’ll be good to go.

That worked! Awesome!
One more question for you. Several of our micro-services use sockets (socket.io). It initially starts in poll mode with http: and then tries to change to ws: protocol. I see this doesn’t happen and then it falls back to http:. Is there something I should be adding to the routes that have this capability?

Forgot to mention, when it tries to switch, Caddy returns with 502 (Bad Gateway)

502 means that Caddy couldn’t connect to your upstream. Make sure those services are running and can accept connections. Use curl -v to try to connect.

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