All Tools View Categories About Contact Privacy

Nginx FastCGI Config Generator

Proxy PHP-FPM over FastCGI via unix socket or TCP.

Runs entirely in your browser - nothing is uploaded and no cloud connection is made.
Your FastCGI server block will appear here.
-
lines
-
blocks

About Nginx FastCGI Config Generator

Running PHP behind nginx means speaking FastCGI to PHP-FPM, and the smallest mistake - a missing SCRIPT_FILENAME, a TCP target that nginx cannot parse, or a regex location that is silently treated as a prefix - produces the dreaded "File not found" or a blank page. The Nginx FastCGI Config Generator builds a correct server block that proxies PHP-FPM over a unix socket or TCP, wiring index, root and the SCRIPT_FILENAME fastcgi_param, then validates the output.

At the heart of the configuration are a handful of directives. fastcgi_pass points nginx at the PHP-FPM socket or TCP endpoint that executes PHP. fastcgi_param passes SCRIPT_FILENAME so PHP-FPM knows which file to run. fastcgi_index sets the script used when the PHP location is requested as a directory. include pulls the standard fastcgi_params snippet for sane default FastCGI variables. root declares the document root nginx serves static files from and resolves scripts against. index names the default entry script tried when a directory is requested. Together they shape how the server behaves, and the tool assembles them in the right context so the result is valid on the first try.

Common mistakes are easy to make. Forgetting SCRIPT_FILENAME makes PHP-FPM reject requests with "File not found", so the generator always emits it. A unix socket path that is not absolute makes nginx fail to start, so the tool requires a leading slash. A TCP target without a valid host:port cannot be parsed, so the generator validates both halves. A mis-escaped \.php$ regex location is treated as a prefix and can match wrong files, so the tool emits the correct escape. The generator anticipates each of these and either sets a safe default or rejects the input with a clear message before anything is written to your clipboard.

Validation is strict because small configuration errors fail in subtle ways. Every input is checked for plausibility, and after the block is assembled it is re-parsed by a built-in tokenizer so unbalanced braces, missing semicolons or stray characters cannot reach your clipboard. Stat cards report line and block counts, and copy, download and print exports are one click away. Everything runs in your browser; nothing you type is transmitted to any server.

In practice this block drops into any standard nginx install. Save the output as a file under /etc/nginx/conf.d/ (or sites-available with a symlink), run nginx -t to confirm the syntax, then reload with nginx -s reload. Because the generator emits a single, self-contained server block with no hidden dependencies, it composes cleanly with your existing caching, logging and security configuration without directive collisions.

Beyond producing correct config, the tool is a reference you can read back and learn from. Each control maps to a real nginx directive, the sample button shows a complete working block in seconds, and clearing the form resets every field to its safe default. Standardising on a generator like this removes per-developer variation, keeps your configuration readable, and gives you a repeatable, auditable setup that passes nginx -t on the first try.

When something looks wrong in production, the first move is always to re-run nginx -t and inspect /var/log/nginx/error.log; most failures surface there with a line number. The access log records every request, so a sudden spike or a wall of 499 responses points straight at backend or timeout problems the generator helps you avoid in the first place.

This server block is designed to sit alongside - not fight - your other configuration. Because it declares its own server_name and a single, self-contained set of directives, you can drop it into conf.d without worrying about collisions with global caching, logging or security snippets that live elsewhere in the nginx tree.

For a production site, pair this block with TLS termination: serve on 80 for the redirect or health checks, and place the encrypted listener (or a front-end load balancer / CDN) in front so clients always speak HTTPS. The generator keeps that boundary clean so the two layers compose instead of overlapping.

If a change ever needs to be undone, the output is plain text you control: delete the file from conf.d, re-run nginx -t, and reload. There is no database and no hidden state, so rolling back is as simple as restoring the previous version from version control or your own backup.

Performance and correctness both benefit from explicit configuration. Defaults baked into the generator reflect current best practice rather than decades-old forum snippets, so the block you ship today will not surprise you with deprecated directives or insecure fallbacks six months from now.

For teams, a generated block is also documentation. New engineers can read the exact directives in place, compare them against the sample, and learn the relevant nginx behaviour without reverse-engineering a hand-maintained file that drifted from its original intent.

Features

  • fastcgi_pass - points nginx at the PHP-FPM socket or TCP endpoint that executes PHP.
  • fastcgi_param - passes SCRIPT_FILENAME so PHP-FPM knows which file to run.
  • fastcgi_index - sets the script used when the PHP location is requested as a directory.
  • include - pulls the standard fastcgi_params snippet for sane default FastCGI variables.
  • root - declares the document root nginx serves static files from and resolves scripts against.
  • index - names the default entry script tried when a directory is requested.
  • Self-verifying output re-parsed before display.
  • Copy, Download and Print exports.
  • Load-sample button fills realistic values.
  • Statistics cards for quick checks.
  • Runs entirely in your browser - nothing uploaded.

How to Use

  1. Enter the public domain the block serves.
  2. Set the document root as an absolute path.
  3. Set the index file, typically index.php.
  4. Choose the PHP-FPM transport (unix or tcp).
  5. Enter the FPM target: socket path or host:port.
  6. Click Generate (or Load sample) and review the block.
  7. Drop it into conf.d and run nginx -t.

Examples

Example 1 - Unix socket domain example.com proxying /run/php/php-fpm.sock over unix - a standard PHP host.

Example 2 - TCP FPM FPM reachable at 127.0.0.1:9000 over TCP.

Example 3 - Relative root rejected a root without a leading slash is reported as an error.

Example 4 - Bad TCP target a target without a port is rejected with a clear message.

Example 5 - SCRIPT_FILENAME present the generated block always includes the SCRIPT_FILENAME param.

Benefits

  • Correct FastCGI block for unix or TCP FPM.
  • SCRIPT_FILENAME always wired correctly.
  • Validates socket path and TCP host:port.
  • Regex PHP location emitted with proper escape.
  • Self-checked output re-parsed before display.
  • Private: everything runs in your browser.

Frequently Asked Questions

Unix socket or TCP?
A unix socket avoids TCP overhead and is common on the same host; TCP is handy when PHP-FPM runs on another container or machine.
What is SCRIPT_FILENAME?
It tells PHP-FPM which file to execute by combining the document root and the requested script name; without it you get "File not found".
Why include fastcgi_params?
That file ships sensible defaults (headers, script name, etc.) so you do not hand-write every parameter.
Why the regex location?
location ~ \.php$ matches PHP requests only; the escape must be correct so nginx treats it as a regex, not a prefix.
What does try_files do?
It serves static files and falls back to 404, preventing PHP execution of non-existent scripts.
Can I change the index file?
Yes - set index to index.php or any other entry script; the generator uses it for both index and fastcgi_index.
Is the output validated?
Yes - the block is re-parsed by a built-in tokenizer before display.
Is anything uploaded?
No. Everything runs locally in your browser.