Why Nginx before PHP-FPM: preparing a server for several applications

From prepared directories and ACLs to the Nginx role: separate public roots, static files, PHP-FPM and handling an unknown Host.

One gateway directs blue and teal paths to two separate public compartments.
One gateway directs blue and teal paths to two separate public compartments.

The training VPS already has separate frontend and admin directories, service accounts and access permissions. We now need to decide which process will accept a web request and which part of an application it may reach. We are preparing Nginx for that role: serving public files and forwarding application requests to the appropriate PHP-FPM.

This is an architecture decision before installing the web server. The completed E‑01 exercise verified filesystem permissions; the Nginx configuration, PHP-FPM pools and HTTP responses still need to be configured and tested.

Two applications, two public roots

Frontend and admin may belong to one product, yet their files and mutable data have separate boundaries. E‑01 has an individual tree for each. Their public directories are represented below:

/srv/solution200/products/lab/frontend/public
/srv/solution200/products/lab/admin/public

The illustrative root directive for the future frontend server block is:

root /srv/solution200/products/lab/frontend/public;

This is one line of a future configuration, rather than a complete server block. The root directive sets the directory used to construct a file path. Our model uses public, rather than the entire application containing code, cache and configuration.

The web server and PHP execution have separate roles

Nginx can serve a static file itself. To execute PHP, it forwards a request to a FastCGI server, which will be PHP-FPM in this model. That connection needs its own configuration; creating a public directory does not establish it. The FastCGI module documentation describes this forwarding.

The intended request flow can be represented as follows. This is a diagram, not a transcript of completed HTTP requests:

HTTP request
  -> Nginx: select the application
       -> a static file in its public directory
       -> a request to the corresponding PHP-FPM

Access to public files therefore does not require the web process to read all application configuration. The PHP process will have its own runtime identity and mutable directories.

Permissions we can already build on

In the filesystem exercise, www-data represented the future web process. Tests opened files and listed directories under its UID. The table summarizes the observed results:

OperationResult on E‑01
Read a training file in publicAllowed
Modify that fileDenied
Read the private training env markerDenied
List var/cacheDenied

These are filesystem permissions. They provide a foundation for the web server, while an HTTP route still needs a separate test through the selected server block, its rules and the actual process.

The hostname also needs an explicit policy

Nginx matches a request against server blocks for an address and port and considers the hostname. An unknown name may reach the default server. Its behaviour therefore needs an explicit decision. The request processing guide explains the selection order.

For several applications, the intended domain must lead to its own public root, and an arbitrary Host must not silently expose a neighbouring application. Practical configuration needs both requests: one with the expected name and one with an unknown name.

Why this Nginx role

We are preparing an origin server for several applications. We need explicit connections between a web hostname, a public directory and a PHP runtime. That task determines the Nginx configuration; comparing web server names alone does not resolve it.

The next practical step is to install the web server and test those connections on E‑01. The permissions already prepared remain the foundation: the web process reads public content, while each runtime works with its own mutable data.

  1. Operations & Security ACLs on Debian: allow public files and protect the private tree
  2. Architecture Debian service users: a separate identity for each application
  3. Architecture Nginx on Debian: two public roots and HTTP access checks
  4. Architecture An application layout in /srv: code, public files, and writable data
  5. Operations & Security Nginx and PHP-FPM: two applications and the right worker

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article