HTTP Path Rewrites

If you want to host Redpanda Console under a subpath rather than the root path, you need to configure HTTP path rewrites. This allows you to serve Redpanda Console under a subpath of your domain, such as https://my-company.com/redpanda/console, instead of directly from https://my-company.com. This type of configuration is often necessary when:

  • You have multiple services and applications running under the same domain.

  • Redpanda Console is behind a reverse proxy. The proxy might add a path prefix based on routing rules, and Redpanda Console needs to know about this prefix to handle requests correctly.

If you host Redpanda Console at a root path, for example under a sub-domain such as https://console.redpanda.my-company.com, you don’t need to configure HTTP path rewrites.

Configuration

To configure HTTP path rewrites, set the following properties within the server object in your Redpanda Console configuration file:

Configuration Description Default

basePath

The subpath under which Redpanda Console is hosted.

If you have a proxy in front of Redpanda Console that sets the X-Forwarded-Prefix header and setBasePathFromXForwardedPrefix is enabled, you do not need to set basePath manually.

''

setBasePathFromXForwardedPrefix

Tells Redpanda Console to use the X-Forwarded-Prefix header on incoming requests for determining the path prefix.

If this header is present, its value will be used as the path prefix, and the value set in basePath will be ignored.

true

stripPrefix

Removes the specified prefix from the request path before routing it to Redpanda Console.

If your proxy is configured to remove the prefix, you should disable stripPrefix in Redpanda Console.

true

Custom subpath scenario

Consider the following setup where you want to host Redpanda Console at https://my-company.com/redpanda/console/ and are using a reverse proxy to manage the routing:

  1. Nginx is configured to route requests from /redpanda/console to Redpanda Console, running on http://localhost:8080.

    Redpanda Console configuration
    server:
      setBasePathFromXForwardedPrefix: true
      stripPrefix: true
    Nginx configuration
    location /redpanda/console/ {
        proxy_pass http://localhost:8080/;
        proxy_set_header X-Forwarded-Prefix /redpanda/console;
    }
  2. A user navigates to https://my-company.com/redpanda/console/topics in their browser.

  3. Nginx receives the request and recognizes the /redpanda/console subpath. It forwards the request to Redpanda Console at http://localhost:8080/topics, while adding the X-Forwarded-Prefix: /redpanda/console header.

  4. Because setBasePathFromXForwardedPrefix is set to true, Redpanda Console checks the X-Forwarded-Prefix header. It identifies that the base path is /redpanda/console and removes this prefix from the incoming request path. The request path /topics is now correctly routed in Redpanda Console.

If Nginx were configured without the X-Forwarded-Prefix header, or if setBasePathFromXForwardedPrefix was set to false, Redpanda Console would not correctly recognize the subpath, leading to routing issues. This configuration is particularly useful when multiple environments or proxies might route to the same Redpanda Console instance under different subpaths.

Prefix removal scenario

Some proxies, such as Traefik, can remove a prefix from the URL path before forwarding it. If both the proxy and Redpanda Console attempt to remove the prefix, Redpanda Console may fail to route the request correctly. Only one part of the stack (either the proxy or Redpanda Console) should remove the prefix.

To better understand this problem, consider the following scenario:

  1. Traefik is configured to route /topics to Redpanda Console with the "StripPrefix" middleware enabled.

  2. Redpanda Console is configured with the default settings, which includes stripPrefix: true.

  3. A user enters the following address in their browser: example.com/topics/topics/example-topic.

  4. Traefik removes the first /topics from the path, leaving /topics/example-topic, and sets /topics in the X-Forwarded-Prefix header.

  5. Redpanda Console sees the X-Forwarded-Prefix and attempts to remove what it thinks is the prefix. The path becomes /example-topic.

  6. Redpanda Console then tries to find a handler for /example-topic, but no such route exists, leading to a failure.

To avoid this issue, either disable stripPrefix in Console or ensure that the proxy does not modify the request path in a conflicting manner.

Proxy rewrites

If you have a reverse proxy between Redpanda Console and Kafka Connect, ensure that any rewrite rules retain the necessary expand parameters in the query string. These parameters are crucial for Kafka Connect to return the correct details about the connectors:

://<kafka_connect_host>:8083/connectors?expand=info&expand=status

This ensures that Redpanda Console can correctly communicate with Kafka Connect even when hosted behind a proxy that rewrites URLs.