Strange Redirect issue with Reverse Proxy

1. The problem I’m having:

So I’m using the Reverse proxy in caddy to direct a custom domain with SSL using Caddy. The original site looks something like this:

The original site is hosted at, and so on and if a user visits (the root without /path), they’re automatically directed to

And so with the caddy, I wish to accomplish Reverse proxy with SSL with the domain where directs to and redirects to

(Caddyfile attached below)

The SSL works successfully and is issued but for some strange reason, when is entered in the browser, instead of displaying contents from, the page is redirected to

Since I’m using a React JS app with React router configured as follows, is this an expected issue?

2. Error messages and/or full log output:

No errors but page redirects

3. Caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

4. How I installed and ran Caddy:

I installed on EC2 using serverless:

 #!/bin/bash -xe
 sudo wget -O /usr/bin/caddy ""
sudo chmod +x /usr/bin/caddy
sudo groupadd --system caddy
sudo useradd --system --gid caddy --create-home --home-dir /var/lib/caddy --shell /usr/sbin/nologin --comment "Caddy web server" caddy

a. System environment:

Amazon 2 Linux

b. Command:

Command above

c. Service/unit/compose file:

See the commands above

d. My complete Caddy config:

        order rewrite after forward_auth
        admin off
        on_demand_tls {
                ask {env.DOMAIN_SERVICE_ENDPOINT}

        storage_clean_interval 90d


:80 {
        respond /health "Im healthy" 200


:443 {
        tls {env.EMAIL} {

        forward_auth {env.ENDPOINT} {
                uri /?sourceHost={host}&extraUri={uri}
                header_up Host {upstream_hostport}
                copy_headers Pathroute Domainroute Domainhttpsroute


        rewrite * {header.Pathroute}

        try_files {path} /index.html

        reverse_proxy {header.Domainroute}:443 {
                header_up Host {}
                header_up User-Custom-Domain {host}

                header_down Cache-Control max-age=5184000

                health_timeout 5s

                transport http {


forward_auth endpoint file with hardcoded values for testing:

exports.handler = async (event) => {
    let statusCode;

    let pathRoute = '';

    if (event.queryStringParameters && event.queryStringParameters.hasOwnProperty('sourceHost')) {
      const extraUri = event.queryStringParameters.extraUri;
      if(extraUri==='/' || !extraUri || extraUri===''){
        pathRoute = '/dashboard1';
        pathRoute = extraUri

      statusCode = 200;
    } else {
      statusCode = 400;

    return {
        headers: {
          'Pathroute': pathRoute,
          'Domainroute': '',
          'Domainhttpsroute': '',
        statusCode: 200,

If your JS is redirecting, then obviously it’ll redirect. Don’t do that then.

But based on my assumption when doing a reverse proxy with caddy for a site, does it not fetch the results from that page and directly send it over to or it only builds after fetching?

I don’t understand the question.

Okay to put it more elaborately, in the above code, I’ve ensured that when a request to the caddy server comes from, for the first time the page should be proxied to, it must serve that specific route in the React application (as you can see in the forward_auth config, I append /dashboard1 for the first request)

But the opposite seems to happen, the result appears the same regardless of whether I do the condition check and by default the React app seems to serve the page for ‘/’ path instead of doing it for ‘/:wallUrl’ since the first time the rewritten URI would be

TLDR; Both & when proxied through Caddy show the same page while it should present different results. Is this peculiar to React since React-Router is used? Or is it the default behavior of Caddy?

Do you see debug logs for rewrite happening?

Yeah I do but never mind I found a workaround for this just by writing the appropriate “Route” logic in the React app since the routing happens on client side

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