Reverse_proxy http -> https site

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

a. System environment:

I run caddy with systemctl:
ExecStart=caddy run --eviron --config
ExecReload=caddy reload --config

b. Command:

caddy reload to reload my config =)

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 Caddyfile or JSON config:

(cloudflare) {
  tls {
    dns cloudflare <token>
  }
}

(logs) {
  log {
    level DEBUG
    output file <logpath> {
      roll_size 100mb
      roll_keep 2
      roll_keep_for 72h
    }
  }
}

http://sunnybanlist.axi92.at {
  import cloudflare
  rewrite * /axi92/sunny-banlist/master/banlist.txt
  reverse_proxy https://raw.githubusercontent.com
  import logs
}

3. The problem I’m having:

I play a game (ark) that can operate a banlist from an weburl but it is only working over http not https. So I try to serve a raw github file over http with caddy.
I like to access http://sunnybanlist.axi92.at and it shows me the content of https://raw.githubusercontent.com/axi92/sunny-banlist/master/banlist.txt but always keeps http because the gameserver only can access http…

4. Error messages and/or full log output:

grafik

{
  "level": "error",
  "ts": 1624491808.2654796,
  "logger": "http.log.access.log0",
  "msg": "handled request",
  "request": {
    "remote_addr": "172.68.110.12:11370",
    "proto": "HTTP/1.1",
    "method": "GET",
    "host": "sunnybanlist.axi92.at",
    "uri": "/",
    "headers": {
      "Cf-Ray": [
        "664194294d091e61-MUC"
      ],
      "X-Forwarded-Proto": [
        "http"
      ],
      "User-Agent": [
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
      ],
      "Pragma": [
        "no-cache"
      ],
      "Cache-Control": [
        "no-cache"
      ],
      "Accept-Encoding": [
        "gzip"
      ],
      "X-Forwarded-For": [
        "x.x.x.x"
      ],
      "Cf-Visitor": [
        "{\"scheme\":\"http\"}"
      ],
      "Accept-Language": [
        "de,en-US;q=0.7,en;q=0.3"
      ],
      "Dnt": [
        "1"
      ],
      "Cookie": [
        "cf_ob_info=525:664193ef0ac41e65:MUC; cf_use_ob=0"
      ],
      "Connection": [
        "Keep-Alive"
      ],
      "Cf-Request-Id": [
        "0adcdaedcc00001e61233a6000000001"
      ],
      "Cf-Ipcountry": [
        "AT"
      ],
      "Cf-Connecting-Ip": [
        "x.x.x.x"
      ],
      "Cdn-Loop": [
        "cloudflare"
      ],
      "Accept": [
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
      ],
      "Upgrade-Insecure-Requests": [
        "1"
      ]
    }
  },
  "common_log": "172.68.110.12 - - [24/Jun/2021:01:43:28 +0200] \"GET / HTTP/1.1\" 404 5142",
  "duration": 0.024755508,
  "size": 5142,
  "status": 404,
  "resp_headers": {
    "Accept-Ranges": [
      "bytes"
    ],
    "Date": [
      "Wed, 23 Jun 2021 23:43:28 GMT"
    ],
    "X-Served-By": [
      "cache-fra19144-FRA"
    ],
    "Vary": [
      "Accept-Encoding"
    ],
    "Content-Security-Policy": [
      "default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'"
    ],
    "Content-Length": [
      "5142"
    ],
    "Content-Type": [
      "text/html; charset=utf-8"
    ],
    "X-Github-Request-Id": [
      "696A:0342:222D5D:26BA81:60D3C2AB"
    ],
    "Via": [
      "1.1 varnish"
    ],
    "X-Cache": [
      "HIT"
    ],
    "X-Fastly-Request-Id": [
      "dfcd6277c5eaf7cfe579259a3811be3a5eb98982"
    ],
    "Server": [
      "Caddy",
      "GitHub.com"
    ],
    "X-Cache-Hits": [
      "1"
    ],
    "Content-Encoding": [
      "gzip"
    ],
    "Age": [
      "1141"
    ],
    "X-Timer": [
      "S1624491808.268492,VS0,VE1"
    ],
    "Etag": [
      "W/\"5f7bc6b3-239b\""
    ]
  }
}

5. What I already tried:

6. Links to relevant resources:

Two things.

If your site is HTTP only, don’t import cloudflare, because that’s trying to tell Caddy to turn on HTTPS for an HTTP site. It’s a contradiction.

Next, if you proxy to a different site over HTTPS, then you need to override the Host header for the proxy requests to use the same domain as the upstream instead Caddy’s default of passing through the Host header from the original request (your domain).

reverse_proxy https://raw.githubusercontent.com {
	header_up Host {http.reverse_proxy.upstream.hostport}
}

Thank you, that one line was all that I needed. :raised_hands:
And cloudflare supports http only. It is working now the way that I wanted =)

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