Introducing a new way to review your PRs.

Read the announcement

frappe / frappe_docker

Docker environment for developing, deploying, and running Frappe applications (ERPNext and custom apps) in production and development

View on GitHub

15 documents · Updated Nov 23, 2026

docs / runtime-startup-and-web-serving

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 roleRuntime purposeInternal endpoint or command
BackendHandles Frappe web requestsGunicorn on 0.0.0.0:8000
WebsocketHandles Socket.IO connectionsNode process on port 9000
Queue workersRun short and long background jobsbench worker queues
SchedulerTriggers scheduled workbench 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.

HeaderBrowser control
X-Frame-Options: SAMEORIGINLimits framing to the same origin.
Strict-Transport-SecurityRequests strict HTTPS use for two years and includes subdomains.
X-Content-Type-Options: nosniffStops MIME-type guessing.
X-XSS-ProtectionEnables the legacy browser XSS filter in block mode.
Referrer-PolicyLimits 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 sites path aligned. A mismatch can hide image-built assets when the volume is mounted.
  • Keep Gunicorn's listen address and port aligned with the frontend BACKEND value 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 SOCKETIO value, 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-Name header 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

TriggerConsequenceGuard
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

FileWhy to read it
resources/…/main-entrypoint.shShows the shared volume preparation that runs before service commands.
resources/…/start.shShows the default backend process and its runtime tuning inputs.
resources/…/nginx-entrypoint.shShows how runtime values and defaults become the active Nginx configuration.
resources/core/nginx/nginx-template.confDescribes the public file, backend, websocket, and proxy request paths.
resources/core/nginx/security_headers.confDefines the browser-facing security header set.
compose.yamlConnects service commands, internal endpoints, shared volumes, and startup dependencies.
images/production/ContainerfileShows how the production image packages Nginx and the runtime entrypoint scripts.
images/layered/ContainerfileShows the equivalent runtime contract for layered images.