Bitbucket Server context-path configuration when reverse proxy strips path prefix
0 reputation · 29 Jun 2021, 09:14 UTC
0 reputation · 29 Jun 2021, 09:14 UTC
Configure Bitbucket Server or Data Center behind a reverse proxy that removes the context-path prefix (e.g., maps /bitbucket/* to /*) so that HTTP clone URLs, REST endpoints, and static resources resolve correctly.
server.context-path but does not specify whether the value should match the external URL path (e.g., /bitbucket) or the internal path seen by the application (e.g., /).X-Forwarded-Prefix header (standard in Spring Boot 2.3+), so the application cannot detect the original prefix from the proxy./, which may fail if server.context-path is set to a non-root value.server.context-path be set to the external path (e.g., /bitbucket) or the internal path (e.g., /)?X-Forwarded-Prefix header for automatic context-path detection?When the reverse proxy removes the external prefix (e.g., maps /bitbucket/* to /*), set server.context-path to the internal path seen by the application – typically an empty value (or /) meaning the root of the Tomcat container.
Bitbucket builds its URLs (clone links, REST endpoints, static resources) from server.context-path and the configured Base URL. If the proxy strips the prefix, the application receives requests at / internally. Setting server.context-path to the external prefix would cause double‑prefixing (e.g., /bitbucket/bitbucket/...) and break clone/fetch operations.
X-Forwarded-Prefix; however, starting with Spring Boot 2.3 (Bitbucket 7.x) you can enable forwarded‑header handling by adding server.use-forward-headers=true to bitbucket.properties (or via JVM args).server.context-path is empty, use /status; if you retain a non‑root context, use <context-path>/status.<BITBUCKET_HOME>/shared/bitbucket.properties (or <BITBUCKET_INSTALL>/bin/setenv.sh for JVM args) and set:
# Internal path – empty because proxy strips the prefix
server.context-path=
# Enable forwarding of X‑Forwarded‑* headers (requires Bitbucket 7.x+)
server.use-forward-headers=true
https://proxy-host/bitbucket (include the context‑path that the proxy presents).X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Port, and X-Forwarded-Prefix (the latter is the original /bitbucket prefix). Example NGINX snippet:
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Prefix /bitbucket;
server.context-path is empty: GET https://internal-node-host/status.GET https://internal-node-host/<context-path>/status.https://proxy-host/bitbucket; the UI loads without redirect loops.https://proxy-host/bitbucket/scm/... and a git clone succeeds.https://proxy-host/bitbucket/rest/api/1.0/... returns expected JSON.{"state":"RUNNING"} with HTTP 200.ssh://git@proxy-host:7999/project/repo.git works unchanged.Please confirm your Bitbucket version (7.x or later) to verify that the server.use-forward-headers=true workaround applies. If you are running an older version (6.x or earlier), the forwarded‑header support is not available and you would need to retain the context‑path internally (i.e., set server.context-path=/bitbucket) and adjust the proxy to not strip the prefix.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.