Running HAPI FHIR behind a reverse proxy or load balancer

Placing a HAPI FHIR JPA server behind a reverse proxy or load balancer needs a correct public server address, TLS at the edge, and deliberate CORS and ETag handling. This page covers the decisions and setup order.

On this page

Why a HAPI FHIR reverse proxy setup needs its own plan

A hospital, digital health company or payer that exposes a HAPI FHIR JPA server through a reverse proxy or load balancer has to decide what address clients see before the server goes live. The server builds absolute links, including the self link and the full URLs in Bundle entries, from the address it receives on each request. If the proxy terminates TLS, rewrites the path or forwards traffic from an internal host name, those generated links can point at an address that clients cannot reach or should not trust. Setting the public server address is therefore a configuration decision in its own right, not a detail left to the ingress defaults.

Teams usually need this plan in four situations: when TLS terminates at the proxy and the server speaks plain HTTP internally, when a single public host serves several applications through path-based routing, when browser-based apps call the API and need correct CORS and ETag behavior, and when several server instances sit behind one load balancer. Each situation adds headers, forwarding rules or caching behavior that must agree with the server configuration. Confirm with your platform team exactly which forwarded headers your proxy or ingress controller sets and whether it overwrites or appends values supplied by the client.

The exact behavior depends on the proxy or load balancer you choose, including how it handles forwarded headers, path prefixes and response caching. The HAPI FHIR documentation describes the server-side settings, but the proxy configuration is specific to your platform and must be tested against real Bundle responses. Ask your team to record the public base URL, the internal address, the headers that cross each hop and a sample of links from a search response, and to verify them before any client application is pointed at the endpoint.

How a client request reaches the HAPI FHIR server through the proxy

A browser app or EHR client sends a request to the public address, where the load balancer or reverse proxy terminates TLS, answers CORS preflight, and routes the path to a HAPI FHIR JPA instance. Each instance reads the shared database, and the forwarded headers and public base URL travel back so links and Bundle entries point to the public address. Check that the proxy sets those headers and that every instance agrees on the same public base URL.

Requests pass through the proxy to shared JPA instances, and responses carry public URLs back.

Which proxy and public address options fit which environment

This table compares a Kubernetes ingress controller, a standalone reverse proxy in front of a Tomcat or Spring Boot instance, and a cloud load balancer across TLS handling, path prefixes, header forwarding and CORS placement. Read each row as a question to answer for your environment, then confirm the named configuration keys in the starter documentation before choosing. The main takeaway is that the public address must match whichever layer terminates TLS and rewrites paths, or Bundle links will point at internal addresses.

Decision pointKubernetes ingress with the Helm chartStandalone reverse proxy in front of Tomcat or Spring BootCloud load balancer in front of the instance
Where TLS terminatesUsually at the ingress controller using a certificate secret, with the pod serving plain HTTP inside the clusterAt the proxy host, which then forwards to the application over HTTP or re-encrypted HTTPSAt the managed load balancer, often with certificates managed by the cloud provider
Path prefix handlingIngress path rules and rewrite annotations decide whether a prefix reaches the pod; confirm the chart's base path settingsProxy location blocks strip or keep the prefix; the application must know the same external pathListener and target group rules route by path; the instance receives whatever path the balancer forwards
Forwarded headersIngress controllers set forwarding headers by default in most setups; confirm the trusted proxy settings the starter readsYou must set X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-Port explicitly and trust only your own proxyBalancer adds forwarding headers; check that the application trusts only the balancer address range
Public base address for linksSet the external host and scheme in starter configuration so Bundle entries and self links are correctSet the same external base address and confirm the forwarded-header trust settings in application.yamlSet the balancer's DNS name as the public address and verify self links after the first request
CORS placementCan be handled at ingress or in the server; avoid duplicate Access-Control headers from both layersCan be set in the proxy or in the starter's CORS settings; pick one owner and test preflight requestsOften configured on the balancer or a web application firewall; confirm which layer answers OPTIONS requests
ETag and caching headersIngress must pass ETag and Cache-Control headers through unchanged; confirm no default caching rule strips themProxy caching must be off for FHIR responses unless you have reviewed cache keys and authorizationCheck whether the balancer or CDN caches responses that carry authorization
Operational ownerPlatform team owns the ingress and certificates; the application team owns server settingsInfrastructure team owns the proxy; configuration drift between proxy and application is the common failureCloud team owns the balancer; coordinate changes with the application's public address setting

Setting the public server address so Bundle links are correct

The HAPI FHIR server builds every absolute URL it returns, including the self and next links in search Bundles and the fullUrl of each Bundle entry, from the address it believes it is serving. Behind a reverse proxy or load balancer, the address the container or application server sees is often an internal hostname and plain HTTP port. Unless the server is told the external scheme, host and context path that clients use, every link it returns points somewhere the client cannot reach. The server must therefore be configured with the public base URL and must read the forwarded headers the proxy sets, so that the scheme, host and path reflect the client-facing request.

A mismatch usually shows up in client behavior rather than as a server error. A paged search returns a next link that uses http or an internal name, so the client's follow-up request fails or bypasses the proxy and its TLS and access rules. Bundle fullUrl values can also break clients that resolve references between entries. To verify the setting, run a search through the proxy, for example a Patient search with _count set low enough to produce a next link, then inspect the link and fullUrl values in the response. Repeat the same request directly against the application port to confirm the difference. Also confirm that the proxy forwards the standard forwarded headers and that the application is configured to trust them only from the proxy's address.

The property names, the header handling and the context path settings vary by starter version, so confirm them against the configuration reference for the version you deploy before go-live. Check the values in application.yaml or the equivalent environment variables, and record the exact public base URL in your deployment runbook. Upgrades are a common point of regression, because a new version can change how forwarded headers are read. Keep this check in your post-upgrade test set.

CORS and ETag handling for browser-based FHIR apps

Browser-based FHIR apps depend on headers that the server, the proxy, or both must set and pass through unchanged. The cards below cover the parts of that contract that most often break when a reverse proxy sits in front of HAPI FHIR.

Allowed origins and preflight

Browsers send a preflight OPTIONS request before cross-origin calls that use custom headers or methods such as PUT and PATCH. Your allowed origins list must match the exact scheme, host and port of each app, and the proxy must answer preflight requests without forwarding them to a backend that rejects them. Confirm the CORS configuration key names and defaults for your HAPI FHIR version, and test preflight with curl before testing in a browser.

HAPI FHIR security docs

Exposing ETag and Location

Scripts can only read response headers that the server lists as exposed to the browser. If ETag and Location are not in the exposed headers list, a single-page app cannot read the version of a resource it just fetched or the address of a newly created one. Check that the CORS layer, not only the backend, sets this list, and that the proxy does not strip it on the way back.

Conditional requests with If-Match

Clients use If-Match with the ETag value to update a resource only if it has not changed, and If-None-Match to avoid re-downloading unchanged data. Both headers must be allowed in the preflight response for browser requests. Test a stale If-Match update through the public address to confirm the server returns a conflict rather than overwriting data.

Headers stripped or cached by the proxy

Reverse proxies and CDNs can remove custom response headers, add their own CORS headers that duplicate the server's, or cache responses without respecting ETag validation. Duplicate Access-Control-Allow-Origin values cause browsers to reject responses. Review the proxy's header rules, caching policy and buffering settings, and capture a full response through the proxy to compare it with a direct call to the server.

Where CORS is enforced

You can enforce CORS in HAPI FHIR, in the proxy, or in both. Enforcing it in one place keeps the policy simple, but the proxy may answer preflight before the server sees the request, so a server-side policy alone can be bypassed for direct API clients only in the sense that it does not restrict them. Decide which layer owns the allowed origins list, document it, and keep the two copies from drifting apart during upgrades.

Setup sequence for a proxied HAPI FHIR server

This sequence takes a HAPI FHIR JPA server from a private address to a public, TLS-protected endpoint where generated links, browser apps and path-based routes all work as intended. Each step ends with a check you can run before moving on.

  1. Fix the public base URL and context path

    Before touching configuration, the platform owner and the integration lead agree on the one public address clients will use, including scheme, host and any path prefix such as /fhir. Every generated link, Bundle entry and capability statement URL will be built from this value, so changing it later affects stored references your consumers may already hold. Write the decision into the runbook with the owner's name. Done when the agreed base URL is written down and a test request to the public host is expected to resolve to the FHIR root path.

  2. Configure forwarded headers and the server address

    The platform engineer sets the server's public address in application.yaml or environment overrides so the server does not echo internal hostnames or plain HTTP schemes back to clients. Confirm in the HAPI FHIR and Spring Boot configuration documentation which forwarded-header settings your chosen container or application server needs, since the exact keys depend on the version and deployment method you run. Done when a request sent through the proxy returns a self link that uses the public https address rather than the internal one.

  3. Terminate TLS at the edge with a certificate lifecycle

    The network or platform team terminates TLS at the load balancer, ingress or reverse proxy, and the security team defines who issues, renews and rotates the certificate, and how expiry is alerted on. Decide whether traffic between the proxy and HAPI FHIR stays on plain HTTP inside a trusted segment or is re-encrypted, and record that decision because it affects audit scope. Done when an external TLS scan shows a valid chain for the public host, the renewal owner is named, and an expiry alert is configured.

  4. Set CORS for each browser origin

    The application team lists each browser origin that calls the FHIR API, such as a clinician portal or patient app domain, and configures CORS on the HAPI FHIR server to allow only those origins and the methods and headers they need. Avoid wildcard origins for endpoints that return patient data. Confirm the CORS options and the ETag exposure settings for your version in the HAPI FHIR documentation before enabling them. Done when a preflight OPTIONS request from an approved origin succeeds, and a request from an unlisted origin receives no allow-origin header.

  5. Configure path-based routes at the proxy

    The platform engineer maps public paths to backend services, for example sending the FHIR base path to the HAPI FHIR pods and other paths to other applications, and confirms that path rewriting does not strip or add segments the server expects. Keep the rules in version control so they are reviewed like any other change. Done when a request to each route reaches the intended backend, and a request to an unmapped path returns an error from the proxy rather than reaching the FHIR server.

  6. Verify the capability statement through the proxy

    The integration lead requests the metadata endpoint through the public address and checks that the returned capability statement lists the expected FHIR version and that its URLs point to the public base URL. Compare the result with a direct request to the internal address to confirm the only difference is the host. Done when the metadata response matches the agreed base URL and FHIR version exactly.

  7. Verify search, create and conditional update

    Using a test client with a non-production account, the team runs a search, a create and a conditional update through the proxy, and checks that the returned Bundle entries, Location headers and ETag values use the public address. Repeat the create and update with a browser-origin request to confirm the CORS and ETag headers reach the browser. Record the request and response pairs in the runbook. Done when every call returns the expected status code and the links contain no internal hostnames.

Security considerations at the proxy boundary

The reverse proxy is the first thing an attacker meets and the place where client identity, TLS and request limits are decided. HAPI FHIR does not provide a single security layer, so the proxy plan has to support the authentication and authorization the operator adds behind it. The cards below cover the decisions to make and the checks to run before go-live.

Trust boundaries for forwarded headers

The proxy sets headers such as X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-For, and the server uses them to build public URLs and client addresses. Configure the proxy to overwrite these headers on every inbound request rather than passing through values supplied by the client. Confirm which forwarded headers the server trusts, and restrict the network path so only the proxy can reach the server directly. Without this, a client can spoof its address or the scheme in links.

TLS protocol and cipher policy

Decide the protocol versions and cipher suites at the edge, and record them in a configuration that your security team can review. Disable legacy protocol versions and weak ciphers, and confirm the certificate chain is complete for browser clients and for any system-to-system callers. Ask your security team which baseline they require, and test the result with an external scanner before go-live.

Encryption between proxy and server

TLS ends at the proxy by default, so traffic from the proxy to the HAPI FHIR server crosses the internal network in clear text unless you configure it otherwise. For patient data, decide whether that hop must be encrypted under your network policy, and if so, plan the server certificate and trust store. Document the decision, because auditors and security reviewers will ask where protected health information travels unencrypted.

Rate limiting and request size limits

FHIR bundles, batch transactions and bulk operations can be large, and search requests can be expensive. Set request body size limits and rate limits at the proxy for each route, and align them with the server's own limits so that rejected requests fail clearly. Test with a large batch and a burst of search calls, and confirm that the limits do not break legitimate clinical workflows such as bulk loads from integration engines.

Access logs without patient identifiers

Proxy access logs record the full request URL by default, and FHIR search parameters often contain names, identifiers and dates of birth. Configure the log format to omit or hash query strings for patient-related paths, restrict who can read the logs, and set a retention period agreed with your privacy office. Check that the server's own audit logging, such as BALP, is still recorded separately, since the proxy log is not a substitute for it.

Authentication sits with the operator

HAPI FHIR does not supply one security layer. It provides building blocks such as authentication interceptors, the AuthorizationInterceptor, consent and search narrowing interceptors, and CORS support, which you assemble and test. The proxy must pass the headers or tokens those components need, and must not strip the Authorization header or block paths that carry OAuth or SMART flows. Review this design with your identity team before routing is finalized.

HAPI FHIR security docs

Path-based routing when FHIR shares a domain with other services

When the FHIR server owns a host or a dedicated hostname, such as a single FHIR base at the root of its own domain, the proxy forwards requests without rewriting the path. The base URL is simply the public origin plus the FHIR base path the server exposes. This is the simplest layout to verify because every link the server generates, including Bundle entry full URLs, next links and Location headers, should match that origin once the public server address is set. Most of the risk comes from the proxy changing the scheme or host, not the path.

  • Public address: Set the server's public base URL to the externally visible HTTPS address so generated links do not point at an internal host or port.
  • Forwarded headers: Confirm the proxy sends the standard forwarded headers for host and protocol, and that the application is configured to trust them from that proxy only.
  • Redirects: Check that any redirect the server issues keeps the HTTPS scheme and the public host.
  • Static assets: If the server serves a web interface, confirm its asset paths resolve from the root.
  • Path stripping: Confirm no prefix rewriting occurs, since a stripped path can produce links that omit the expected base.

Before go-live, request a search and read a Bundle through the public address and confirm every generated URL uses that address. Confirm the exact configuration keys for your starter version.

Limits and what to confirm in your environment

The proxy settings in this topic depend on the HAPI FHIR version you run, the platform in front of it, and the hosting constraints of your organization. The cards below list what to verify in your own environment instead of assuming it. Public demonstration servers and vendor support help with questions, but they do not confirm how your proxy behaves.

Starter release and version behavior

Confirm how your chosen HAPI FHIR version and starter release read forwarded headers and build the server base URL. Behavior around Forwarded, X-Forwarded-Proto and X-Forwarded-Host has changed between releases, so test a sample Bundle and a Location header after each upgrade. Check JDK requirements against the versions page before you pick the base image, since the required JDK depends on the release. Record the tested combination in your change log.

Versions page

Proxy and ingress feature support

Confirm which features your load balancer, ingress controller or API gateway provides before you rely on them. Check path rewriting, header injection, TLS termination, response header handling and whether CORS preflight requests pass through unchanged. Some managed load balancers cache responses or strip ETag headers by default. Ask the platform team for the exact configuration keys and test each behavior with a browser client.

Session behavior with stateless instances

Confirm whether your load balancer uses cookie or source-address affinity, and whether that matters for your clients. The JPA server is designed to run as several instances on a shared database, but in-memory state such as subscription caches stays per instance. If you use sticky sessions, test failover when one instance is removed. Ask the platform team how session affinity is configured and how long it lasts.

Request and body size limits

Confirm the maximum request body size, header size and timeout at every hop, including the proxy, the ingress, the application server and any web application firewall. Large Bundles, batch transactions and bulk operations can fail with a generic error when one layer rejects them first. Run a test with the largest payload your clients send, and confirm that the error a client receives is a clear status code rather than a dropped connection.

Hosting environment constraints

Confirm the constraints your hosting environment imposes on TLS certificates, allowed ports, network segments and DNS names. Some data center or cloud networks restrict which hosts can reach the database or which paths are exposed publicly. Ask your security team whether the public address must sit on an internal or external zone, and who renews and rotates the certificate. These rules decide which proxy layout is possible.

Public demo and vendor support

The public demonstration server at hapi.fhir.org and vendor support from Smile CDR can answer questions about the software, but neither tests your proxy. Your own URL, certificate chain, CORS policy and header handling are specific to your setup. Use a staging environment that matches production routing, and run the checks in this topic against it before you publish the address to clients.

HAPI FHIR README

Questions teams ask before running HAPI FHIR behind a proxy

How much effort does a reverse proxy setup for HAPI FHIR take?

Effort depends mostly on how many public origins you serve, how TLS is terminated, whether you run one tenant or several, and what ingress or load balancer you already operate. A single origin with TLS at an existing load balancer is a small change, mainly setting the public server address so Bundle links and self references are correct. Each extra origin, custom CORS rule for a browser app, or path-based route adds configuration and test cases. Multitenant setups that map partitions to hostnames or paths take the most design work. Ask any partner to break the estimate down by these drivers rather than quoting a single figure.

Can our internal team set up HAPI FHIR behind a proxy without outside help?

Often yes, if your team already runs load balancers, certificates and Java application servers, and has someone who understands FHIR server URLs and headers. The HAPI FHIR configuration is small compared with the surrounding network work. The harder parts are usually the ones outside the application: agreeing on the public hostname, correcting forwarded headers at every hop, and proving that browser clients can read ETag and paging links. A partner is most useful when several teams must agree on the design, when the platform sits in a regulated environment with formal change control, or when no one has run a FHIR server in front of a browser app before.

What does the work need from our teams before it starts?

Plan to involve four groups early. Network and platform engineers must confirm which load balancer or ingress receives traffic, which hops sit between it and the server, and which headers each hop adds or strips. DNS owners must assign the public hostname and any path prefix. Certificate or PKI owners must issue or approve the TLS certificate and decide where it terminates. Security and compliance reviewers must sign off on CORS origins, exposed headers and whether TLS is re-encrypted to the server. Ask for a written list of these owners and their change windows before scheduling any work.

How long does a proxy setup take depending on our existing infrastructure?

Duration is driven by what already exists. If you have a managed ingress with certificates automated and a clear hostname plan, the application-side change is typically short, and most time goes to testing and change approval. If you must create new DNS records, procure certificates, or introduce a new gateway, the lead time is set by those teams and their approval cycles, not by HAPI FHIR. Environments with several origins, separate test and production change control, or unclear ownership of the load balancer take longer. Request a timeline that lists each dependency and who controls it.

Which settings change the most between a direct and a proxied deployment?

Three areas cause most of the rework when moving behind a proxy:

  • The public server address, which must match the external scheme, host and path so that Bundle entries, self links and pagination URLs point to the right place.
  • Forwarded headers, so the server reads the original scheme and host from X-Forwarded-Proto and X-Forwarded-Host only from trusted proxies.
  • CORS and ETag handling for browser applications, including exposed headers such as ETag and Location.

Keep these settings in version-controlled configuration so each environment is reviewed the same way. Confirm exact property names against the HAPI FHIR documentation for your version.

How do we verify the reverse proxy setup is correct?

Test from outside the cluster, using the same public hostname that clients will use. Check that the capability statement loads over HTTPS, that a search returns Bundle links with the public scheme and host, and that a paginated search follows next links without reverting to an internal address. From a browser origin, confirm that preflight requests succeed and that the client can read ETag on a read and send If-Match on an update. Confirm that a request sent with a spoofed forwarded header from an untrusted source is ignored. Record the results so the same checks run after each upgrade or load balancer change.

Does DeployOpen handle the proxy configuration and testing for us?

DeployOpen plans, implements, integrates, hardens and documents self-hosted open-source platforms in infrastructure you control, which includes configuring a HAPI FHIR server behind your load balancer or ingress and testing the public address, CORS and ETag behavior. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts, and a quote follows from that written scope. DeployOpen does not issue audit reports or certifications for the resulting setup. Independent assessors and certification bodies perform those assessments, and DeployOpen can prepare the configuration evidence they will ask to see.

How DeployOpen scopes a reverse proxy setup for HAPI FHIR

DeployOpen scopes a reverse proxy setup for HAPI FHIR in writing before any configuration starts. The written scope names the public base address clients will use, the proxy or load balancer that terminates TLS, the certificate source, the browser origins allowed through CORS, the path prefixes that route to the FHIR server, and the verification steps that must pass before go-live. Each item is agreed with your platform, network and security teams, because the public address drives the links the server writes into resources and Bundle entries, and a mismatch there is costly to find after clients have started using the API. Everything is built and tested inside your own cloud accounts, data centers or air-gapped networks, and the scope states which of those environments applies.

The scope also defines what you receive at handover: the proxy configuration as code, the server settings that carry the forwarded headers and public address, a record of the CORS and ETag behavior tested from the browser apps that will call the server, and a runbook for changing the address or certificate later. Ask each proposal to list those artifacts and the test cases behind them. DeployOpen prepares systems, controls and evidence for compliance reviews, such as configuration records, access settings and test results, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies perform those assessments. Ongoing upgrades of the HAPI FHIR server and proxy, and continuous testing of the routing and headers, can be covered by a retainer after the fixed-scope work is complete.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.