gnmyt / myspeed

A speed test analysis software that shows your internet speed for up to 30 days
https://myspeed.dev
MIT License
676 stars 30 forks source link

[Bug] #821

Closed bitbucket90 closed 1 month ago

bitbucket90 commented 1 month ago

General

The Bug

MySpeed Bug Report: 404 Error When Accessing /myspeed

Summary

When accessing the MySpeed application through a Caddy reverse proxy, requests to the /myspeed path result in a 404 (Not Found) error or could not reach the API of this instance error, However, the backend service is accessible and returns the expected content when queried directly.

Environment

Steps to Reproduce

  1. Set up Caddy as a reverse proxy for the MySpeed application.
  2. Configure Caddy to forward /myspeed/* requests to the MySpeed backend.
  3. Start the MySpeed backend service.
  4. Access https://example.com/myspeed in a web browser.
  5. Observe the 404 error.

Expected Behavior

Accessing https://example.com/myspeed should display the MySpeed application interface.

Actual Behavior

Accessing https://example.com/myspeed returns a 404 (Not Found) error. OR I get an API error stating

image

Configuration

Caddyfile

{
    admin 127.0.0.1:2019
    debug
}

:80 {
    redir https://{host}{uri} permanent
}

example.com {
    root * /var/www/example.com
    file_server

    handle_path /myspeed/* {
        reverse_proxy backend-service:5216 {
            header_up Host {http.request.host}
            header_up X-Real-IP {http.request.remote.host}
            header_up X-Forwarded-For {http.request.remote.host}
            header_up X-Forwarded-Proto {http.request.scheme}
        }
    }

    handle /manifest.json {
        reverse_proxy backend-service:5216
    }
    handle /assets/* {
        reverse_proxy backend-service:5216
    }

    encode gzip zstd

    log {
        output file /var/log/caddy/access.log
        format json
        level DEBUG
    }
}

Log Analysis

  1. Caddy logs show 404 errors for /myspeed requests:

    {"level":"debug","msg":"fileserver.(*FileServer).notFound: HTTP 404","request":{"method":"GET","host":"example.com","uri":"/myspeed","headers":{"Accept":["*/*"],"User-Agent":["curl/7.88.1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"status":404}
  2. Direct requests to the backend service succeed:

    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Cache-Control: public, max-age=0
    Last-Modified: Tue, 21 May 2024 22:14:31 GMT
    ETag: W/"40c-18f9d386958"
    Content-Type: text/html; charset=UTF-8
    Content-Length: 1036
    Connection: keep-alive
    Keep-Alive: timeout=5
    
    <!DOCTYPE html>
    <html lang="en">
     <head>
       <meta charset="utf-8" />
       <link rel="icon" href="/assets/img/favicon.ico" />
       ...
     </head>
     <body>
       <div id="root"></div>
     </body>
    </html>

Additional Information

  1. The server is listening on the expected ports (80, 443, 22, 2019).
  2. The backend service is running and accessible when queried directly.
  3. Other routes on the server (e.g., the root path) are working correctly.

Possible Causes

  1. The /myspeed path handling in Caddy may not be correctly configured.
  2. There might be a mismatch between how Caddy is forwarding requests and how the MySpeed application is expecting to receive them.
  3. The MySpeed application may not be properly configured to work under a /myspeed path prefix.

Attempted Solutions

  1. Verified that the backend service is running and accessible.
  2. Checked Caddy configuration for any obvious misconfigurations.
  3. Tested direct access to the backend service to confirm it's working as expected.

Additional Notes

Attachments

  1. Full sanitized Caddy log file
  2. Network configuration output
  3. Curl test results

What device are you using to access the page?

In the browser, On mobile

Which operating system is your MySpeed instance running on?

Linux

bitbucket90 commented 1 month ago

Closed - This is not myspeed related, once I added some for X Forward rules it seemed to have worked.

` # MySpeed configuration handle_path /myspeed* { reverse_proxy 10.0.10.21:5216 { header_up X-Forwarded-Prefix /myspeed header_up Host {http.request.host} header_up X-Real-IP {http.request.remote.host} header_up X-Forwarded-For {http.request.remote.host} header_up X-Forwarded-Proto {http.request.scheme} } }

# Handle all MySpeed related requests
handle /manifest.json {
    reverse_proxy 10.0.10.21:5216
}
handle /assets/* {
    reverse_proxy 10.0.10.21:5216
}

# Additional catch-all for MySpeed static files
handle {
    reverse_proxy 10.0.10.21:5216 {
        header_up X-Forwarded-Prefix /myspeed
    }
}`