Image Variations

FPM-NGINX

The fpm-nginx variation runs NGINX and PHP-FPM in one container, supervised by S6 Overlay. Choose it for Laravel and other PHP apps that run on PHP-FPM when you want the web server included and don't need Apache's .htaccess files or FrankenPHP's worker mode. Compare every variation →

At a glance

fpm-nginx
ProcessesNGINX and PHP-FPM, supervised by S6 Overlay
Ports8080 (HTTP), 8443 (HTTPS)
Stop signalSIGQUIT
Default health checkcurl to http://localhost:${NGINX_HTTP_PORT}${HEALTHCHECK_PATH} (/healthcheck by default)
Webroot variableNGINX_WEBROOT (default /var/www/html/public)
PHP versions8.1 to 8.6
Operating systemsDebian and Alpine

How a request flows through NGINX and PHP-FPM

  1. NGINX receives the request on 8080 or 8443.
  2. If the path matches a file in the webroot, such as a CSS file or image, NGINX serves it directly.
  3. Any other path is rewritten to /index.php, and NGINX passes .php requests to PHP-FPM over FastCGI on 127.0.0.1:9000.
  4. PHP-FPM runs the script and returns the response through NGINX.

S6 Overlay starts PHP-FPM before NGINX and restarts either one if it exits. PHP-FPM answers the /healthcheck route. The default health check fails if either process is down.

Quick start

Put your app's public files in public/, which is the default webroot:

compose.yml
services:
  php:
    image: serversideup/php:8.5-fpm-nginx
    ports:
      - "80:8080"
    volumes:
      - ./:/var/www/html

Run docker compose up and open http://localhost. Mounting your code like this is for development. In production, copy the code into your own image instead; see packaging your app for deployment.

Configuration

These variables are specific to this variation. Defaults and the full list, including every PHP_* and PHP_FPM_* option, are in the environment variable specification.

To changeSet
Document rootNGINX_WEBROOT
Maximum upload or request sizeNGINX_CLIENT_MAX_BODY_SIZE, plus PHP_UPLOAD_MAX_FILE_SIZE and PHP_POST_MAX_SIZE
FastCGI response buffersNGINX_FASTCGI_BUFFERS, NGINX_FASTCGI_BUFFER_SIZE
Log destinationsNGINX_ACCESS_LOG, NGINX_ERROR_LOG
Listening portsNGINX_HTTP_PORT, NGINX_HTTPS_PORT
IPv4 only or IPv6 onlyNGINX_LISTEN_IP_PROTOCOL
NGINX version in response headersNGINX_SERVER_TOKENS

Custom NGINX rules go in server-opts.d

The default site sends missing paths to /index.php and adds security headers. It blocks dotfiles (except /.well-known/) and PHP files under /storage/. Static assets get a one-year cache and gzip is on. To add your own rules, put a .conf file in the folder for the level where the rules belong:

FolderIncluded insideUse it for
/etc/nginx/server-opts.d/Each server {} block that serves your applocation blocks, redirects, add_header
/etc/nginx/conf.d/The http {} blocklimit_req_zone, map, or a whole extra server {}

A location block in conf.d/ stops NGINX from starting with "location" directive is not allowed here. With SSL_MODE=full, the HTTP server only redirects. Rules in server-opts.d/ then apply to HTTPS requests only.

The image already has performance.conf and security.conf in server-opts.d/. A file with the same name replaces the image's rules. Your files are used as written: environment variables such as ${NGINX_WEBROOT} are not filled in.

Example: rate limit an API and redirect an old URL

A rate limit needs two parts: the zone at http level and the limit inside a location.

limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

Mount the files in development. For production, copy them into your image:

services:
  php:
    image: serversideup/php:8.5-fpm-nginx
    ports:
      - "80:8080"
    volumes:
      - ./:/var/www/html
      - ./rate-limit-zone.conf:/etc/nginx/conf.d/rate-limit-zone.conf:ro
      - ./api.conf:/etc/nginx/server-opts.d/api.conf:ro

Requests to /api/ over the limit get a 503.

Replace the whole site

To write the server {} blocks yourself, put your file at /etc/nginx/conf.d/default.conf. When that file exists at startup, the image uses it instead of its own site. You then own everything the default site does, including SSL_MODE handling and the /healthcheck location. Try server-opts.d/ first.

Health checks

The default health check works without configuration. Set HEALTHCHECK_PATH=/up to check Laravel's health route instead. Health checks covers timing and orchestrators. Laravel health checks covers /up and worker containers.

SSL

SSL_MODE=mixed serves HTTP on 8080 and HTTPS on 8443. SSL_MODE=full serves HTTPS on 8443 and redirects HTTP on 8080 to it. The image generates a self-signed certificate unless you provide one. See configuring SSL.