Caddy reverse_proxy serve blank page

1. Caddy version (caddy version):

v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

2. How I run Caddy:

sudo systemctl start caddy

a. System environment:

Linux ip-172-31-29-214 4.4.0-1128-aws #142-Ubuntu SMP Fri Apr 16 12:42:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Xenial

b. Command:


sudo systemctl start caddy

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:


{

debug

}

node-0.t3nx.net {

reverse_proxy / localhost:8080

reverse_proxy /api localhost:5000

reverse_proxy /admin localhost:5000

}

node-0-frontend.t3nx.net {

reverse_proxy localhost:8080

}

node-0-backend.t3nx.net {

reverse_proxy localhost:5000

}

3. The problem I’m having:

I am trying to use Caddy reverse proxy to serve Flutter web app and also Django REST api. I split them by path since I would like to serve it from different service

I serve frontend Flutter web app using

http-server build/web

I serve backend Django api

gunicorn beauty_coin.wsgi --bind 0.0.0.0:5000 --chdir=beauty_coin

curl [https://node-0.t3nx.net](https://node-0.t3nx.net%60%60%60) responses me the source code of page. This url has no problem

4. Error messages and/or full log output:


<!-- Please **DO NOT REDACT** any information except credentials. Leave domain names intact! -->

<!-- Please **DO NOT POST TRUNCATED LOG LINES** as systemd is notorious for this. -->

<!-- Please **DO NOT USE WEB BROWSERS.** Use curl -v instead. -->

<!-- Please **DO ENABLE DEBUG MODE FIRST** by adding "debug" to the global options of your Caddyfile. -->

`curl -v [https://node-0.t3nx.net`](https://node-0.t3nx.net%60) responses blank line

❯ curl -v https://node-0.t3nx.net/admin

* Trying 52.74.149.26:443...

* Connected to node-0.t3nx.net (52.74.149.26) port 443 (#0)

* ALPN, offering h2

* ALPN, offering http/1.1

* successfully set certificate verify locations:

* CAfile: /etc/ssl/cert.pem

* CApath: none

* TLSv1.2 (OUT), TLS handshake, Client hello (1):

* TLSv1.2 (IN), TLS handshake, Server hello (2):

* TLSv1.2 (IN), TLS handshake, Certificate (11):

* TLSv1.2 (IN), TLS handshake, Server key exchange (12):

* TLSv1.2 (IN), TLS handshake, Server finished (14):

* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):

* TLSv1.2 (OUT), TLS handshake, Finished (20):

* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):

* TLSv1.2 (IN), TLS handshake, Finished (20):

* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256

* ALPN, server accepted to use h2

* Server certificate:

* subject: CN=node-0.t3nx.net

* start date: Jan 15 17:02:17 2022 GMT

* expire date: Apr 15 17:02:16 2022 GMT

* subjectAltName: host "node-0.t3nx.net" matched cert's "node-0.t3nx.net"

* issuer: C=US; O=Let's Encrypt; CN=R3

* SSL certificate verify ok.

* Using HTTP2, server supports multi-use

* Connection state changed (HTTP/2 confirmed)

* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0

* Using Stream ID: 1 (easy handle 0x7fbda800b600)

> GET /admin HTTP/2

> Host: node-0.t3nx.net

> user-agent: curl/7.77.0

> accept: */*

>

* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!

< HTTP/2 301

< content-type: text/html; charset=utf-8

< date: Sat, 15 Jan 2022 19:11:44 GMT

< location: /admin/

< referrer-policy: same-origin

< server: Caddy

< server: gunicorn

< vary: Origin

< x-content-type-options: nosniff

< content-length: 0

<

* Connection #0 to host node-0.t3nx.net left intact

5. What I already tried:

I have tried split the URL into [node-0-frontend.t3nx.net](http://node-0-frontend.t3nx.net) and [node-0-backend.t3nx.net](http://node-0-backend.t3nx.net). It works

But when I merge them together to solve CORS problem in Chrome by using [node-0.t3nx.net](http://node-0.t3nx.net). My backend url does not work.

Django urls.py

from django.contrib import admin
from django.urls import path, include
from rest_framework.authtoken.views import obtain_auth_token
from profiles.api.fbvs import welcome, get_balance, send_transaction

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('beauty_coin.api_routers')),
    path('api/auth-token/', obtain_auth_token),
    path('api/welcome/', welcome),
    path('api/balance/', get_balance),
    path('api/send-transaction/', send_transaction)
]

6. Links to relevant resources:

It’s working properly.

You made your request to /admin, and your backend is replying with a 301 redirect to /admin/.

Your server isn’t configured to proxy anything other than /api, and /admin to that backend (and / to another backend), so a request to /admin/ has nothing configured for it.

Be sure to read up on how path matchers work: Request matchers (Caddyfile) — Caddy Documentation

You probably want to append a * to your path matchers.

2 Likes

Thank you very much @matt. Add * and / solve my problem

{
    debug
}
node-0.t3nx.net {
    reverse_proxy / localhost:8080
    reverse_proxy /api/* localhost:5000
    reverse_proxy /admin/ localhost:5000
}

node-0-frontend.t3nx.net {
    reverse_proxy localhost:8080
}

node-0-backend.t3nx.net {
    reverse_proxy localhost:5000
}
1 Like

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