Runtime startup and web serving
The runtime starts each application container by preparing the shared site volume and then running the command assigned to that service. The backend serves Frappe requests through Gunicorn, while the frontend serves files with Nginx and sends dynamic requests or Socket.IO traffic to the matching application process. This page is a child of Container stack architecture; see Compose service topology variants and Networking, TLS, and proxy options for deployment choices around these services.
Container startup
Shared site initialization
The common entrypoint prepares the sites volume before it starts the service command. It replaces the volume's sites/assets path with a symbolic link to the image's baked assets, meaning assets built into the image remain available after the volume is mounted. The entrypoint then uses exec so the selected application process becomes the main container process.
The production and layered images use this entrypoint for their runtime services. The Compose service can still replace it when a service needs a setup command, such as the configurator.
flowchart LR
A[Container starts] --> B[Prepare sites volume]
B --> C[Link image assets into sites]
C --> D[Run service command]
D --> E[Backend, websocket, worker, scheduler, or Nginx process]
References: resources/…/main-entrypoint.sh• L1-14 images/…/Containerfile• L145-165 images/…/Containerfile• L38-58 compose.yaml• L9-18 compose.yaml• L20-44
Service process launch
The default application command launches Gunicorn from the Frappe sites directory on port 8000. Its worker and thread counts plus request timeout come from environment values with safe defaults, so deployment configuration can scale request handling without changing the image. Other Compose services use the same image with commands for Socket.IO, queue workers, and the scheduler.
The configurator runs before services that depend on its completed setup. It writes shared connection and runtime settings into the site configuration. The backend and frontend then use those shared settings and service names to connect within the Compose network.
| Process role | Runtime purpose | Internal endpoint or command |
|---|---|---|
| Backend | Handles Frappe web requests | Gunicorn on 0.0.0.0:8000 |
| Websocket | Handles Socket.IO connections | Node process on port 9000 |
| Queue workers | Run short and long background jobs | bench worker queues |
| Scheduler | Triggers scheduled work | bench schedule |
References: resources/…/start.sh• L4-20 compose.yaml• L20-52 compose.yaml• L54-81 compose.yaml• L83-96
Web request serving
Frontend proxy
The frontend is an Nginx process that listens on port 8080 inside its container. At startup, nginx-entrypoint.sh supplies defaults for the backend address, Socket.IO address, listen port, real-client-IP settings, site-name rule, client body limit, and proxy timeout when those values are not set. It substitutes the resulting values into the Nginx template and keeps Nginx in the foreground. This keeps the image reusable across direct access and external proxy or TLS layouts.
The frontend normally receives backend:8000 and websocket:9000 from Compose. An outer proxy can publish or route the frontend without changing the internal application endpoints; those outer choices are described in Networking, TLS, and proxy options.
References: resources/…/nginx-entrypoint.sh• L3-60 resources/…/nginx-template.conf• L1-29 compose.yaml• L54-72
Request paths
Nginx separates local file delivery from application handling. It serves assets directly, keeps protected-file requests internal, and checks the selected site's public directory before sending a request to the backend. Socket.IO requests use an upgraded HTTP connection and carry the Frappe site name so the websocket process can serve the right site.
When Nginx sends a request to the backend, it preserves the client host and forwarded protocol context. It also asks the backend to use accelerated file delivery for protected responses. URL rewrites remove common trailing and HTML suffix forms before the request is handled.
This diagram shows how an incoming request moves between local file handling and the two application processes.
flowchart TD
R[Incoming request] --> S{Request path}
S -->|/assets| A[Serve asset from shared sites]
S -->|/socket.io| W[Proxy with websocket upgrade]
S -->|Other path| P{Public file exists?}
P -->|Yes| F[Serve site public file]
P -->|No| B[Proxy to Frappe backend]
W --> WS[Socket.IO process]
References: resources/…/nginx-template.conf• L31-78 compose.yaml• L60-69
Security headers
The shared Nginx header set adds browser controls to responses. Nginx includes it for the server and again for sensitive file responses, and always makes the headers apply across response status codes.
| Header | Browser control |
|---|---|
X-Frame-Options: SAMEORIGIN | Limits framing to the same origin. |
Strict-Transport-Security | Requests strict HTTPS use for two years and includes subdomains. |
X-Content-Type-Options: nosniff | Stops MIME-type guessing. |
X-XSS-Protection | Enables the legacy browser XSS filter in block mode. |
Referrer-Policy | Limits referrer detail based on same-origin and cross-origin requests. |
These headers are part of the application frontend. TLS termination and certificate handling can still occur in an outer proxy, as covered by Networking, TLS, and proxy options.
References: resources/…/security_headers.conf• L1-5 resources/…/nginx-template.conf• L15-29 resources/…/nginx-template.conf• L53-65 images/…/Containerfile• L82-85
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the asset link target and the mounted
sitespath aligned. A mismatch can hide image-built assets when the volume is mounted. - Keep Gunicorn's listen address and port aligned with the frontend
BACKENDvalue and with any service or proxy route that reaches it. - Keep the Socket.IO port and service address aligned between the Node command, the frontend
SOCKETIOvalue, and the shared site configuration. - Treat changes to the Nginx template and security header include as changes to the public HTTP contract. Check both direct frontend access and access through an outer TLS or proxy layer.
- Keep any change to the site-name header rule aligned with the site directory used for public files and with the
X-Frappe-Site-Nameheader sent upstream. - Keep the Nginx entrypoint defaults aligned with the template's expected variables. An unset value must not silently change the internal route or client request context.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The mounted sites volume is not prepared by the common entrypoint. | Image-built assets are not visible at the path expected by the application. | Keep the entrypoint active for services that use the shared volume. |
BACKEND points to the wrong service or port. | Dynamic web requests fail even when Nginx is reachable. | Match the frontend value with Gunicorn's internal listener. |
SOCKETIO does not reach the websocket service. | Real-time connections fail while normal HTTP requests can still work. | Keep the Compose service name and port in sync with the Node process. |
| The Nginx template receives an invalid upstream or site-name value. | Frontend startup can fail or requests can map to the wrong site. | Validate the substituted runtime values before starting Nginx. |
| A proxy does not provide the expected real-IP or forwarded-protocol settings. | Logs, client IP handling, redirects, or generated links can show the wrong request context. | Align the outer proxy headers with the Nginx real-IP and protocol settings. |
Key files
| File | Why to read it |
|---|---|
| resources/…/main-entrypoint.sh | Shows the shared volume preparation that runs before service commands. |
| resources/…/start.sh | Shows the default backend process and its runtime tuning inputs. |
| resources/…/nginx-entrypoint.sh | Shows how runtime values and defaults become the active Nginx configuration. |
resources/core/nginx/nginx-template.conf | Describes the public file, backend, websocket, and proxy request paths. |
resources/core/nginx/security_headers.conf | Defines the browser-facing security header set. |
| compose.yaml | Connects service commands, internal endpoints, shared volumes, and startup dependencies. |
images/production/Containerfile | Shows how the production image packages Nginx and the runtime entrypoint scripts. |
images/layered/Containerfile | Shows the equivalent runtime contract for layered images. |