Nginx on Debian: two public roots and HTTP access checks

Install Nginx without a premature start, map two Host names to separate public roots, and test real HTTP responses and ACL recovery.

A transparent gateway splits the flow between two public trays backed by closed compartments.

After preparing directories and ACLs, we installed Nginx on the E‑01 lab server and tested access over HTTP. Frontend and admin use separate public roots. The server listens only on 127.0.0.1:8080: we supply lab names in the Host header without DNS, TLS or a public port.

This step serves static files. PHP-FPM is not installed yet, and the frontend and admin trees contain lab markers rather than deployed applications. This lets us examine how Nginx rules work with the filesystem permissions already in place.

Installation without a premature start

Before making changes, we checked selected-key SSH, password-required sudo and the provider's independent console. Nginx was absent. The APT simulation proposed only two new packages, with no upgrades or removals:

sudo apt-get --simulate --no-install-recommends --no-remove --no-upgrade \
  install nginx=1.26.3-3+deb13u9 nginx-common=1.26.3-3+deb13u9

Before installation, we created a temporary administrator mask, /etc/systemd/system/nginx.service → /dev/null, and a separate /usr/sbin/policy-rc.d owned by root:root with mode 0755. Both objects were absent on our server. An existing policy file must not be replaced with this lab example.

#!/bin/sh
case "$1" in nginx|nginx.service) exit 101;; esac
exit 0

This temporary policy rejects actions specifically for Nginx. The use of policy-rc.d by package systemd scripts is described in the Debian documentation. The mask also kept the service inactive while the package created its default files.

sudo apt-get --assume-yes --no-install-recommends --no-remove --no-upgrade \
  install nginx=1.26.3-3+deb13u9 nginx-common=1.26.3-3+deb13u9
sudo systemctl disable nginx.service

We installed nginx and nginx-common version 1.26.3-3+deb13u9; all other package versions were preserved. The service was still inactive after installation. We disconnected the default sites-enabled/default link while retaining sites-available/default and the packaged welcome page.

Fresh SSH verification of Nginx state; the nginx -t result comes from the earlier configuration step. The frame explicitly labels its summary rather than presenting it as raw output from every command.

Two Host names and two public roots

We wrote the following configuration to /etc/nginx/sites-available/e01-lab-origin.conf and linked it from sites-enabled. The file belongs to root:root and has mode 0644.

server {
    listen 127.0.0.1:8080 default_server;
    server_name "";
    access_log off;
    return 404;
}

server {
    listen 127.0.0.1:8080;
    server_name frontend.example.test;
    root /srv/solution200/products/lab/frontend/public;
    autoindex off;
    disable_symlinks on;
    access_log off;
    location ~ (^|/)\. { return 404; }
    location ~* \.php(?:/|$) { return 404; }
    location / {
        limit_except GET { deny all; }
        try_files $uri =404;
    }
}

server {
    listen 127.0.0.1:8080;
    server_name admin.example.test;
    root /srv/solution200/products/lab/admin/public;
    autoindex off;
    disable_symlinks on;
    access_log off;
    location ~ (^|/)\. { return 404; }
    location ~* \.php(?:/|$) { return 404; }
    location / {
        limit_except GET { deny all; }
        try_files $uri =404;
    }
}

Each lab name maps to its own public directory. A separate default server returns 404 for an unknown Host. Directory listing is disabled, symbolic links are blocked, and dotfile requests and URIs containing .php in the configured pattern are rejected. Server selection is explained in the request-processing documentation.

A new SSH session verifies both server blocks and HTTP 200 for public files. Lab Host headers are explicit and require no DNS records.

Configuration validation and one explicit start

We added a dependency on our existing firewall-loading service in nginx.service.d/20-origin-firewall.conf:

[Unit]
Requires=e01-host-firewall-boot.service
After=e01-host-firewall-boot.service

The name e01-host-firewall-boot.service belongs to our earlier practical step; it is not a standard Debian service. Before starting Nginx, it was already active/exited with a successful result. We made no firewall-rule changes in this step.

Once the configuration was ready, we removed only our own temporary mask and policy file, reloaded unit definitions and validated the configuration:

sudo systemctl daemon-reload
sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

The final two lines are the actual nginx -t result. We then ran sudo systemctl start nginx.service once. The service became active while startup remained disabled. The real master runs as root and the worker as www-data; the only listener is 127.0.0.1:8080. We did not reboot in this step.

Check the server response with a separate request

We made requests inside E‑01 through fresh SSH sessions. To reproduce a check, supply Host explicitly, for example:

curl --noproxy '*' -H 'Host: frontend.example.test' \
  http://127.0.0.1:8080/sample.txt

The actual response body for both lab Host names was:

public-fixture-only

A concise summary of the observed HTTP results:

RequestResponse
GET /sample.txt and /nested/new.txt, correct Host200, exact lab file bytes
HEAD /sample.txt200, no body
GET /.env.local, /.git/config, /src/code.txt, /var/cache/probe404
POST /sample.txt403
GET /sample.txt, unknown Host404
HTTP/1.1 without Host400

For additional checks, we temporarily created a readable dummy probe.php, a .hidden file and a leak symlink to the readable sample.txt in each public directory. All three requests returned 404. The denial controls therefore included objects that actually existed. We removed all six owned markers after the experiment.

A closed ACL does not have to produce HTTP 403

On frontend, we changed only our own lab sample.txt to mode 0600. The request returned 404. After setfacl -m m::r--, it returned 200; the file's inode, bytes, mode and ACL exactly matched the original state.

This result belongs to our particular configuration with try_files and disable_symlinks. A 404 status alone does not establish that the file is absent from disk. We knew its original state, closed read access and verified recovery on the same object. The directives are described in the core HTTP module documentation.

HTTP responses are re-read in a new SSH session. The earlier experiment is labelled separately: closing the ACL produced 404 and explicit recovery restored 200; temporary markers have already been removed.

Fresh verification confirmed that the original tree, users and access settings were preserved. We now have a separately tested static HTTP layer. PHP-FPM, an external domain, TLS and startup enablement remain separate changes.

  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 An application layout in /srv: code, public files, and writable data
  4. Architecture Why Nginx before PHP-FPM: preparing a server for several applications
  5. Operations & Security From nginx -t to a running origin: controlled Nginx startup through the CLI