3

I am trying to use Caddy as a reverse proxy for a Python/Flask/Gunicorn API server running on port 5000.

When I visit http://myipaddress:5000 using my browser I see a response from my API server as expected. However, when I visit http://myipaddress/api, instead of getting the exact same response, we get an error page showing:

Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

What might be causing this problem, and how can we fix it?

/root/path/to/Caddyfile

:80 {

    reverse_proxy /api*  0.0.0.0:5000 {
        header_up Host {http.request.host}
        header_up X-Real-IP {http.request.remote}
        header_up X-Forwarded-For {http.request.remote}
        header_up X-Forwarded-Port {http.request.port}
        header_up X-Forwarded-Proto {http.request.scheme}
    }


    log {
        output file /var/log/caddy/access.log {
                roll_size 1mb
                roll_keep 4
                roll_keep_for 24h
        }
    }
}

Tried running

caddy reload --config ~/path/to/Caddyfile

which gave the output

# caddy reload --config ~/path/to/Caddyfile
2021/02/19 06:56:01.742 INFO    using provided configuration    {"config_file": "/root/path/to/Caddyfile", "config_adapter": ""}
2021/02/19 06:56:01.748 INFO    admin.api   received request    {"method": "POST", "host": "localhost:2019", "uri": "/load", "remote_addr": "127.0.0.1:49868", "headers": {"Accept-Encoding":["gzip"],"Content-Length":["676"],"Content-Type":["application/json"],"Origin":["localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
2021/02/19 06:56:01.748 INFO    admin.api   config is unchanged
2021/02/19 06:56:01.748 INFO    admin.api   load complete

/var/log/caddy/access.log

2021/02/19 07:01:58.132 error   http.log.access.log0    handled request {"request": {"remote_addr": "173.123.123.123:60236", "proto": "HTTP/1.1", "method": "GET", "host": "164.123.123.123", "uri": "/api", "headers": {"Connection": ["keep-alive"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Gpc": ["1"], "Accept-Language": ["en-US,en;q=0.9"]}}, "common_log": "173.123.123.123 - - [19/Feb/2021:07:01:58 +0000] \"GET /api HTTP/1.1\" 404 232", "duration": 0.002260348, "size": 232, "status": 404, "resp_headers": {"Server": ["Caddy", "meinheld/1.0.2"], "Content-Length": ["232"], "Access-Control-Allow-Origin": ["*"], "Date": ["Fri, 19 Feb 2021 07:01:58 GMT"], "Content-Type": ["text/html; charset=utf-8"]}}
2021/02/19 07:01:58.421 info    http.log.access.log0    handled request {"request": {"remote_addr": "173.123.123.123:60236", "proto": "HTTP/1.1", "method": "GET", "host": "164.123.123.123", "uri": "/favicon.ico", "headers": {"Sec-Gpc": ["1"], "Referer": ["http://164.123.123.123/api"], "Connection": ["keep-alive"], "Cache-Control": ["no-cache"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36"], "Accept-Encoding": ["gzip, deflate"], "Accept-Language": ["en-US,en;q=0.9"], "Pragma": ["no-cache"], "Accept": ["image/avif,image/webp,image/apng,image/*,*/*;q=0.8"]}}, "common_log": "173.123.123.123 - - [19/Feb/2021:07:01:58 +0000] \"GET /favicon.ico HTTP/1.1\" 0 0", "duration": 0.000009084, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

0 Answers0