-
Notifications
You must be signed in to change notification settings - Fork 2.3k
query: Fix external prefix and add an e2e test for it #2800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb86080
query: e2e: Test --web.external-prefix
onprem f5bff42
query: e2e: Test both routePrefix and externalPrefix used simultaneously
onprem 09c22f0
query: ui: Fix external prefix handling in UI
onprem c479438
Merge branch 'master' into test-external-prefix
onprem 3559fcb
ui: handle web.external-prefix in React UI
onprem fe380e1
e2e: query: Fix e2e externalPrefix tests
onprem 1113fac
Add changelog and regenerated docs
onprem eb4dff8
query: e2e: close httptest server after test completes
onprem 9cb5eb8
Merge branch 'master' into test-external-prefix
onprem cbb85e7
Make changes according to Giedrius' suggestions
onprem d0ad77c
ui: Fix react development build erroring out
onprem 577fb16
Make changes according to Lucas' suggestions
onprem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| title: Running Thanos behind a reverse proxy | ||
| type: docs | ||
| menu: operating | ||
| slug: /reverse-proxy.md | ||
| --- | ||
|
|
||
| # Running Thanos behind a reverse proxy | ||
|
|
||
| Many times you would like to use a [reverse proxy](https://www.nginx.com/resources/glossary/reverse-proxy-server/) in front of Thanos. There are several reasons to use a reverse proxy such that SSL termination (serve Thanos over HTTPS) and basic authentication. | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## External Prefix and Route | ||
|
|
||
| Before continuing, lets first take a look at two cli flags provided by Thanos, `--web.external-prefix` and `--web.route-prefix`. The External Prefix is useful when you want to prefix all requests from UI with some path. Normally, the web UI would load all static assets from `/static/...`, do API calls on `/api/v1/...` etc. But if we use `--web.external-prefix="thanos"` the UI would prefix each request with `/thanos`. It would try to load all assets from `/thanos/static/...`, do API calls on `/thanos/api/v1/...` and so on. One thing to note here is that `--web.external-prefix` only prefixes the requests and redirects with the specified value, but Thanos is still listening on the root, not the specified sub-path i.e. the API is still accessible at `/api/v1/...` and not at `/thanos/api/v1`. This is where `--web.route-prefix` comes in. If you set `--web.route-prefix="thanos"` every route would get prefixed with the specified value. For example, the API will be accessible on `/thanos/api/v1`. As this is the most common use case when using the `--web.external-prefix`, the default value of `--web.route-prefix` is the value of `--web.external-prefix`. | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| > Note: Using different values for `--web.external-prefix` and `--web.route-prefix` can lead to the web UI not working properly if it is accessed directly (without a reverse proxy). | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Examples | ||
|
|
||
| Lets look into some example scenarios. All examples are using Nginx as a reverse proxy here. | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Serving Thanos on a subdomain | ||
|
|
||
| Serving a Thanos component on the root of a subdomain is pretty straight-forward. Let's say you want to run Thanos querier behind a Nginx server, accessible on domain `thanos.example.com`. A basic Nginx configuration would look like this: | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| http { | ||
| server { | ||
| listen 80; | ||
| server_name thanos.example.com; | ||
|
|
||
| location / { | ||
| proxy_pass http://localhost:10902/; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| events {} | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### Serving Thanos on a sub-path | ||
|
|
||
| Things become a little tricky when you want to serve Thanos on a sub-path. Let's say, you want to run Thanos querier behind an Nginx server, accessible on the URL `http://example.com/thanos`. The Thanos web UI depends on it being accessed on the same URL as Thanos itself is listening. This is because the UI needs to know the URL from where to load static assets and what URL to use in links or redirects. If Thanos is behind a reverse proxy, particularly one where Thanos is not at the root, this doesn't work so well. | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To tackle this problem, Thanos provides a flag `--web.external-prefix`. | ||
|
|
||
| Let's say we have Thanos querier running on the usual port, we need Nginx running with the following configuration: | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| http { | ||
| server { | ||
| listen 80; | ||
| server_name example.com; | ||
|
|
||
| location /thanos/ { | ||
| proxy_pass http://localhost:10902/thanos/; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| events {} | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| With this configuration, you can access Thanos querier on `http://example.com/thanos`. Notice that as we are using `http://localhost:10902/thanos/` as the reverse proxy target, every request path will be prefixed with `/thanos`. To make this work we need t run Thanos querier like | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| thanos query --web.external-prefix="thanos" | ||
| ``` | ||
|
|
||
| It should be noted that now the `/thanos` path prefix would be required for all HTTP access to Thanos. The `/metrics` endpoint would be accessible at `http://localhost:10902/thanos/metrics`. | ||
onprem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.