Skip to content

Reading the Generated Config

The outcome of this chapter is a skill, not a setting: given any proxy host NPM manages, you can open the file it generated and say — in plain words — what nginx will do with a request. This is the ground truth chapter 1 promised. The file below is real: it is the lab's nginx-proxy-manager-lab/generated/proxy_host-1.conf, written by the backend when the lab created its host in transcript t07. Find yours at /data/nginx/proxy_host/<id>.conf inside the container (your ./data folder, in nginx/proxy_host/).

# ------------------------------------------------------------
# app.example.com
# ------------------------------------------------------------

map $scheme $hsts_header {
    https   "max-age=63072000; preload";
}

server {
  set $forward_scheme http;
  set $server         "127.0.0.1";
  set $port           8080;

  listen 80;
  listen [::]:80;

  server_name app.example.com;
  http2 off;

  # Block Exploits
  include conf.d/include/block-exploits.conf;

  access_log /data/logs/proxy-host-1_access.log proxy;
  error_log /data/logs/proxy-host-1_error.log warn;

  location / {
    # Proxy!
    include conf.d/include/proxy.conf;
  }

  # Custom
  include /data/nginx/custom/server_proxy[.]conf;
}

Read it in the order nginx does. The comment banner names the host — every generated file starts this way, which makes a folder of them easy to grep. The map block sits outside the server: it prepares an HSTS header value (chapter 8's strict-transport promise) for the day this host gets a certificate; with no certificate yet, it is inert. Inside server, the three set lines are your form, translated: scheme, forward host and forward port, stored as variables rather than baked into the proxying line — that is why one shared proxy.conf can serve every host. listen 80 (and its IPv6 twin) plus server_name are the matching rule: this block answers requests that arrive on port 80 asking for app.example.com.

The two includes are the personality. block-exploits.conf is the switch you turned on: a list of patterns — classic SQL-injection and file-inclusion probes — that make nginx refuse the request outright. proxy.conf, included inside location /, is the actual proxying: it sets the headers the backend service will see (Host, the X-Forwarded-* family that tells it the original scheme and visitor) and ends with the one line that does the work:

proxy_pass $forward_scheme://$server:$port$request_uri;

— your three form fields, arriving at their destination. The two log lines give this host its own access and error logs under /data/logs/, in the proxy format NPM defines in its main configuration. And the last include, custom/server_proxy[.]conf, is an escape hatch that matches nothing until you create that file yourself — chapter 12 uses its cousins.

How the lab knew this file was sound: it did not take the backend's word for it. The backend's own test only exercised the sandbox's default nginx configuration, which never reads this file — so the lab built a small standalone harness (nginx-proxy-manager-lab/harness/) that mirrors the pieces of NPM's real main configuration this file depends on (the $forward_scheme and forwarded-proto maps, the proxy and standard log formats) and includes the generated file the way production does. Two adjustments were needed, both recorded in transcripts t09–t13: the /data/... paths were repointed into the lab (the sandbox has no /data volume), and the http2 off; line had to come out for the sandbox's older nginx 1.24.0, which predates that directive — off is the default, so nothing changed in meaning. With those, a real nginx answered: syntax is ok … test is successful. The redirection host's file passed the same harness (transcript t13).

The check, for your own install: pick any host, open its file, and find your form answers in the three set lines. Then run the test the way NPM does, inside the container — docker compose exec app nginx -t — and expect the same test is successful. You now own the habit this whole guide rests on: when the interface and reality disagree, read the file.