The reverse proxy and TLS#
The Empowerment Center frontend is both the web application server and the reverse proxy to the backend. This page explains how to publish it with TLS, alone or behind the organization's proxy, which headers it sets and removes, how to replace it with another web server and how to share the load among several backend instances.
The frontend variables#
| Variable | Default | What it is |
|---|---|---|
ECENTER_BACKEND_URL |
http://backend:8080 |
The backend, without a trailing slash. |
ECENTER_RESOLVER |
127.0.0.11 |
The DNS with which the backend name is resolved on each request: Docker's or, in Kubernetes, the cluster's. This way a backend that restarts with another address is still found. |
ECENTER_CLIENT_MAX_BODY_SIZE |
100m |
The largest body accepted. It must be at least ECENTER_MAX_UPLOAD, the largest file the backend accepts (100MB). |
ECENTER_BEHIND_PROXY |
off |
on if there is another proxy in front. |
ECENTER_CSP_MAP_ORIGINS |
(empty) | The base map origins, separated by spaces (https://api.maptiler.com). |
ECENTER_CSP_IDP_ORIGINS |
(empty) | The origins of the identity provider to which SAML sign-out sends a form, separated by spaces. |
In deploy/compose.yaml, the last four are taken from deploy/.env.
Two ways to set up TLS#
A load balancer, a Traefik or the organization's proxy receives HTTPS and sends the traffic to the frontend over HTTP.
- Set
ECENTER_BEHIND_PROXY=onindeploy/.envand recreate the frontend. - Configure the proxy in front to send everything for its name to
http://<server>:<ECENTER_HTTP_PORT>/, without changing the path. - Make the proxy in front set
X-Forwarded-Proto,X-Forwarded-Host,X-Forwarded-PortandX-Forwarded-For, and remove those the client brings. - Make it overwrite
X-Forwarded-Forwith the address it sees, instead of adding it to the one the client brings. - Set HSTS (
Strict-Transport-Security) on that proxy.
With on, the frontend respects the X-Forwarded-* it receives and adds its own address to X-Forwarded-For. The backend takes the first address of that list as the client's: if the proxy in front does not overwrite it, each client chooses with which address it appears in the audit and in the sessions.
The frontend receives users directly, with ECENTER_BEHIND_PROXY=off (the default). It calculates the X-Forwarded-* itself and does not trust those the client brings.
For it to terminate TLS itself:
- Copy the image's template,
/etc/nginx/templates/default.conf.template(in the sources,frontend/nginx/ecenter.conf.template), for example todeploy/nginx/default.conf.template. -
In the copy, replace
listen 8080;with these three lines: -
Mount the modified template over the image's one and the certificate in
/etc/nginx/tls/, and publish8443instead of8080. With Docker Compose, in adeploy/compose.override.yaml:services: frontend: volumes: - ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro - ./tls:/etc/nginx/tls:ro ports: !override - "443:8443"!overridereplaces the ports ofcompose.yamlinstead of adding to them (Docker Compose 2.24 or later). With-f deploy/compose.yaml, also add-f deploy/compose.override.yamlto each command. -
Recreate the frontend.
nginx runs unprivileged (user 101): that user must be able to read the certificate key. Keep everything else of the template in your copy: the paths that go to the backend, the headers and the ECENTER_* variables, which the image substitutes at startup. When upgrading ECenter, compare your copy with the new template.
What goes to the backend#
The frontend sends these paths to the backend, untouched, and serves the web application on all the others:
| Prefix | What it is |
|---|---|
/api/ |
The API. |
/embed/ |
The embedding page, the print mode of the headless browser and the embedding SDK. |
/.well-known/oauth-protected-resource/ |
The MCP server's metadata. |
/oauth2/, /login/oauth2/ |
The OIDC round trip. |
/saml2/, /login/saml2/ |
The SAML round trip, and its sign-out. |
/ayuda/ is the manuals, which the frontend itself serves (see The manuals at /ayuda/), with the English ones at /ayuda/en/; /ayuda without a slash redirects to /ayuda/. The rest is the web application: the file, if it exists, and if not index.html.
Headers#
Toward the backend, the frontend sets Host and the four X-Forwarded-* (its own, or those of the proxy in front with ECENTER_BEHIND_PROXY=on), and always removes three headers that the client could choose and that the backend also reads:
| Header removed | Why |
|---|---|
Forwarded |
The backend would prefer it to the X-Forwarded-* for the address, the name and the scheme. As the frontend removes it, the proxy in front has to give the X-Forwarded-*: Forwarded is not used. |
X-Forwarded-Prefix |
It would change the path of redirects. |
X-Forwarded-Ssl |
It would change the scheme. |
With that data the backend rebuilds the original request: the identity provider's return addresses, secure cookies behind TLS and the client address that the audit and the sessions record.
Toward the browser, the frontend sets on the web application:
| Header | Value |
|---|---|
X-Frame-Options |
DENY |
Content-Security-Policy |
frame-ancestors 'none': nobody can frame the application. |
X-Content-Type-Options |
nosniff |
Referrer-Policy |
strict-origin-when-cross-origin |
Content-Security-Policy-Report-Only |
The complete content policy, with the origins of ECENTER_CSP_MAP_ORIGINS and ECENTER_CSP_IDP_ORIGINS. |
Permissions-Policy |
It turns off what the application does not use: accelerometer, camera, screen capture, geolocation, gyroscope, HID, magnetometer, microphone, MIDI, payment, serial port and USB. Fullscreen and the clipboard remain. |
The manuals at /ayuda/ carry the same headers, with their own content policy (also report-only): their inline scripts go by their hash, which is calculated when building the image.
To what comes from the backend it sets none: the embedding page carries its own frame-ancestors with the origins of each host application, and another header would break it. If you put another proxy in front, it must not add framing headers to the /embed/ paths either.
The content policy#
In version 8.0 the content policy only reports: whatever violates it appears in the browser developer tools console and is neither blocked nor sent anywhere. Check yours like this:
- Open the application with the browser developer tools open, in the console tab.
- Go through what is used in your installation: a map with its base map and, if there is SAML, signing out of the application.
- If a warning “… violates the following Content Security Policy directive …” appears, add the origin it names to
ECENTER_CSP_MAP_ORIGINSorECENTER_CSP_IDP_ORIGINSand recreate the frontend.
Cache, compression and timeouts#
- The application's fingerprinted files (
main-….js,chunk-….js,styles-….css) are cached for a year; fonts, for a day;index.htmland the rest are checked again on each visit. After an upgrade, users load the new version when reloading. - In the manuals, fingerprinted files are cached for a year, fonts for a day, screenshots for an hour, and pages and the search index are checked again on each visit.
- Everything goes compressed, including the GeoJSON and the map tiles.
- Timeouts toward the backend are 300 s between two reads. A long download (the audit export can last up to 30 minutes) is not cut off while data keeps arriving. A proxy in front should not cut it off earlier.
Another web server instead of the frontend#
If the organization already has its own proxy (nginx, Apache, HAProxy or a Kubernetes Ingress), it can serve the web application with it:
- Copy the application files to the web server (the
dist/frontend/browserfolder of the build, or the contents of/usr/share/nginx/htmlof the frontend image). - Send the paths of What goes to the backend to the backend, without changing the path.
- Serve
index.htmlon any other path that is not a file. - Set its headers on the web application and leave those of the backend untouched.
- Set the
X-Forwarded-*, overwriteX-Forwarded-Forand removeForwarded,X-Forwarded-PrefixandX-Forwarded-Ssl. - Adjust the timeouts (300 s) and the maximum body size (at least
ECENTER_MAX_UPLOAD). - If you want the manuals, serve at
/ayuda/the site thatmanuales/construir.shleaves inmanuales/site/(or the contents of/usr/share/nginx/ayudaof the frontend image), with the English manuals inside it, inen/.python3 frontend/nginx/help-site.py manuales/site /ayuda/ help-csp.confremoves the printable version and the PDFs, puts the prefix in its error page and writes its content policy. - Tell the backend where to read
index.htmlfor embedding withECENTER_EMBEDDING_INDEX_LOCATION: a URL that serves it (http://frontal/index.html) or a file (file:/srv/ecenter/frontend/index.html).
Several backend instances#
Jobs and their results live in the memory of the instance that calculates them, so the load balancer must always send the requests of the same client to the same instance. The affinity key is, in this order:
- the
X-ECenter-Embed-Sessionheader, sent by an embedded document and by the headless browser; - the
Authorizationheader, of the query API and the MCP; - the
SESSIONcookie, of the application.
With nginx, replacing proxy_pass $ecenter_backend in the backend paths with proxy_pass http://ecenter_backend:
map "$http_x_ecenter_embed_session|$http_authorization|$cookie_SESSION" $ecenter_affinity {
"~^(?<embed>[^|]+)\|" $embed;
"~^\|(?<bearer>[^|]+)\|" $bearer;
default $cookie_SESSION;
}
upstream ecenter_backend {
hash $ecenter_affinity consistent;
server backend-1:8080;
server backend-2:8080;
}
Each instance carries its ECENTER_INSTANCE_NAME and its own headless browser. What the instances share and what they do not is in Architecture.
Common problems#
| Symptom | Cause | What to do |
|---|---|---|
After signing in with the identity provider, it rejects the return address, or the return goes to http:// instead of https://. |
The backend does not receive the original scheme or name. | With a proxy in front, ECENTER_BEHIND_PROXY=on and that proxy must set X-Forwarded-Proto and X-Forwarded-Host. Without containers, SERVER_FORWARD_HEADERS_STRATEGY=framework. |
| The audit and the sessions record the proxy's address, not the user's. | The proxy in front does not set X-Forwarded-For, or ECENTER_BEHIND_PROXY=on is missing. |
Configure it as in Two ways to set up TLS. |
| An external data upload fails with 413. | The file exceeds ECENTER_CLIENT_MAX_BODY_SIZE or ECENTER_MAX_UPLOAD, or the limit of a proxy in front. |
Raise all three at once. |
| Embedding is not shown in the host application. | A proxy in front adds X-Frame-Options or frame-ancestors to /embed/. |
Remove those headers from the backend paths. |
| With several instances, a cube stays loading or disappears when moving to another window. | The load balancer distributes without affinity. | Configure the affinity of Several backend instances. |