Caddy doesn't redirect from HTTP to HTTPS

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

sudo caddy run

a. System environment:

Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal

d. My complete Caddyfile or JSON config:

redacted.com:8080 {
  # redir http://* https://{host}{uri}
  file_server browse
}

3. The problem I’m having:

Caddy does not redirect my http requests to https:

❯ curl -IL http://redacted.com:8080
HTTP/1.0 400 Bad Request

❯ curl -IL https://redacted.com:8080
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Server: Caddy
Date: Thu, 23 Jul 2020 12:01:12 GMT

I have tried adding different directives for http and https, but those are not supported:

cannot natively multiplex HTTP and HTTPS

Hi @NightMachinary, welcome to the Caddy community.

The error is important to note; Caddy indeed does not support HTTP and HTTPS on the same port at the same time.

Remember that Caddy is HTTPS by default; as long as you’re not specifying the scheme (http://) or the default HTTP port (:80) in your site address, Caddy will serve the site you specified, as HTTPS.

So, if port 8080 is being used for HTTPS, a different port has to be used for HTTP (by default this is port 80).

Did you try issuing a request to port 80? Did you get a response from Caddy? I would expect a request for http://example.com:80 to receive a Location: https://example.com:8080 response.

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