Skip to content

http: Taking advantage of X-Forwarded-Prefix #5228

@raskyld

Description

@raskyld

Is your feature request related to a problem? Please describe

When exposing VictoriaMetrics behind a reverse proxy on a specific path, we can take advantage of -http.pathPrefix-like flags which allow VictoriaMetrics http servers to handle requests on this specific prefix.

This is convenient when all VictoriaMetrics endpoints are exposed under the same path.
More complex pattern would fail, though. (e.g. to expose the vmui under /ui but the query paths under /query)

Describe the solution you'd like

An emerging practice came from some reverse proxy implementation (Traefik and YARP) which is to pass to the backend a X-Forwarded-Prefix containing the prefix that led a request to be forwarded to a particular backend.

The backend would not see the prefix in the path of the incoming request because the reverse proxy would have stripped the prefix. Instead, the handlers should be aware of the X-Forwarded-Prefix and adapt their responses' relative URLs (e.g. path to .js and static assets) accordingly by prefixing their relative URLs with the content of X-Forwarded-Prefix.

More than enabling more complex pattern like the one described before, the cognitive load for the user would be lighter because VictoriaMetrics exposed behind a reverse-proxy that implements the X-Forwarded-Prefix semantic would work out-of-the-box without manually passing the -http.pathPrefix flag.

Describe alternatives you've considered

No response

Additional information

This is my first issue in this repo but I would gladly try to implement it and submit a PR.
For example, by adding a -http.UseXForwardedPrefix flag that would enable VictoriaMetrics to use the header, or a disable flag if we want this behaviour to be enabled by default.

As I said, the practice is emerging so I would understand if you didn't want this feature, if so, feel free to tell me and close the issue. I will join some references that I used to create this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy