3

我正在尝试使用 Caddy 作为在端口 5000 上运行的 Python/Flask/Gunicorn API 服务器的反向代理。

当我http://myipaddress:5000使用浏览器访问时,我看到了来自我的 API 服务器的预期响应。但是,当我访问 时http://myipaddress/api,我们没有得到完全相同的响应,而是得到一个错误页面,显示:

未找到 在服务器上未找到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。

什么可能导致这个问题,我们该如何解决?

/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
        }
    }
}

试过跑步

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

这给出了输出

# 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"]}}
4

0 回答 0