Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Nginx FastCGI proxying sends a request to a FastCGI application server such as PHP-FPM instead of serving the application code itself. The fastcgi_pass directive selects the backend listener, while fastcgi_param builds the parameter environment the application needs. A working configuration therefore has three essential parts: a location that matches the request, a fastcgi_pass endpoint that really exists, and a correct SCRIPT_FILENAME mapping to the script on the FastCGI server’s filesystem.

The configuration below covers PHP-style deployments, but the same routing model applies to other FastCGI applications. Socket names, ports, document roots and parameter requirements are deployment-specific; copy the structure, then substitute values exposed by your own FastCGI service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What FastCGI proxying does in Nginx

The ngx_http_fastcgi_module allows Nginx to pass HTTP requests to a FastCGI server. Nginx remains the client-facing HTTP server: it accepts the connection, chooses a location, constructs FastCGI parameters, sends the request to the configured backend and returns the backend response to the client.

FastCGI is an application-backend protocol, not an HTTP reverse-proxy exchange. That distinction is why a FastCGI location uses fastcgi_pass and fastcgi_param rather than the HTTP-oriented proxy_pass and proxy_set_header pattern.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
Directive or pattern What it selects or sends Typical use
proxy_pass An HTTP-oriented upstream URL Proxying to an application that speaks HTTP
fastcgi_pass A FastCGI hostname and port, IP and port, UNIX socket, or upstream group Sending requests to PHP-FPM or another FastCGI listener
proxy_set_header HTTP request headers Preserving headers for an HTTP backend
fastcgi_param FastCGI name/value parameters, including request metadata Providing script paths, query strings and method information

In a PHP request, Nginx does not execute the PHP file. It calculates the script path, passes that path and other request information to PHP-FPM, and PHP-FPM executes the script. The response then travels back through Nginx, which applies its buffering, timeout and error-handling settings before sending the result to the browser.

The minimum PHP-style configuration

A practical baseline is:

location ~ .php$ {
    fastcgi_pass unix:/run/php/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

The socket path in this example is not universal. Replace it with the UNIX socket or TCP listener that PHP-FPM actually exposes. The fastcgi_pass directive accepts a hostname or IP plus port, a UNIX-domain socket, or the name of an upstream server group.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prerequisites

  • Nginx must be installed and able to load the FastCGI module.
  • A FastCGI server must be running and listening on the endpoint you plan to use.
  • The Nginx worker and the FastCGI service must have compatible access to the application files. A path that exists in one isolated environment but not the other still produces a script-resolution failure.
  • Your server block must define the intended root, because the baseline SCRIPT_FILENAME expression uses $document_root.

Step 1: identify the real listener

Inspect the FastCGI service configuration or process manager and record whether it listens on a UNIX socket or TCP address. Use that exact value after fastcgi_pass. A stale socket filename, wrong port, or mismatch between a container and the host is a connection problem, not a PHP script problem.

Step 2: create a matching location

The regular-expression location above matches URIs ending in .php. If your application has a different entry-point convention, adjust the location deliberately. Nginx’s location-selection rules determine which directives run, so a more specific or differently ordered location can prevent the FastCGI block from handling the request you expected.

Step 3: include parameters and set the script path

include fastcgi_params supplies the standard parameter definitions available in your installation. Set SCRIPT_FILENAME explicitly to the filesystem path the FastCGI server should execute. The expression $document_root$fastcgi_script_name combines the configured document root with the script name derived from the request URI.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Step 4: validate and reload

  1. Check the configuration with nginx -t. Correct syntax errors before reloading.
  2. Reload Nginx using the service manager used by your operating system, then request a known PHP script.
  3. If the request fails, inspect the Nginx error log and the FastCGI service log together. The two logs distinguish an unreachable listener from an invalid script path or an application-level failure.

How Nginx maps a URI to a script

The most important mapping is SCRIPT_FILENAME. PHP uses this parameter to determine which file to execute. For a document root of /data/www and a request for /index.php, the expression $document_root$fastcgi_script_name produces /data/www/index.php. That complete path is what the FastCGI server receives.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

$fastcgi_script_name and directory indexes

$fastcgi_script_name is based on the request URI. When the URI ends in a slash and fastcgi_index is configured, Nginx appends the index filename. With fastcgi_index index.php, a request for a directory can resolve to an index.php script. The resulting value must still be valid below the configured document root.

PATH_INFO applications

Some applications use a script followed by additional path information, such as /index.php/articles. In that case, fastcgi_split_path_info accepts a two-capture regular expression. The first capture becomes $fastcgi_script_name; the second becomes $fastcgi_path_info. Pass the latter as PATH_INFO when the application expects it.

location ~ ^(.+.php)(/.+)$ {
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/run/php/php-fpm.sock;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

The regular expression must match the URL shape your application actually uses. If it captures too much or too little, Nginx can hand the backend a script path that does not exist.

Why a wrong path causes “Primary script unknown”

That message generally means the FastCGI service received a SCRIPT_FILENAME that it could not resolve. Compare the value Nginx computes with the path visible from the PHP-FPM process’s filesystem perspective. Common causes include a document root typo, a container path that differs from the host path, a missing index suffix, or a PATH_INFO expression that captured the URI incorrectly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

FastCGI parameters: what the application receives

fastcgi_param creates the FastCGI parameter environment. HTTP request headers are represented as FastCGI parameters, and you can supply additional application-specific values. The module documentation identifies SCRIPT_FILENAME and QUERY_STRING as the minimum PHP-related settings.

Parameter Purpose When it matters
SCRIPT_FILENAME Absolute script path to execute Every PHP-style script request
QUERY_STRING Request parameters after the question mark Requests that use query arguments
REQUEST_METHOD HTTP method such as GET or POST Especially important for form submissions and APIs
CONTENT_TYPE Media type of the request body POST and other requests carrying encoded data
CONTENT_LENGTH Length of the request body POST requests and other body-bearing methods
PATH_INFO Path suffix separated from the script name Applications using PATH_INFO routing

For POST failures, verify that REQUEST_METHOD, CONTENT_TYPE and CONTENT_LENGTH are being passed in addition to the script and query-string parameters. A page that works for GET but fails for a form submission often has an incomplete parameter environment rather than a broken socket.

Choosing a backend endpoint

UNIX-domain socket

A UNIX socket is addressed with a path such as unix:/run/php/php-fpm.sock. It must exist at the path Nginx uses, and permissions must allow the Nginx worker to connect. Distribution packages and service pools commonly choose different filenames, so do not treat the sample path as a standard.

TCP listener

A TCP endpoint uses a host and port, for example 127.0.0.1:9000, when the FastCGI service listens there. Confirm the address from the runtime configuration. A listener bound only to another interface or network namespace is unreachable from Nginx even when the port number looks correct.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Upstream server group

For multiple FastCGI backends, define an upstream group and pass its name:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
upstream php_backends {
    server 127.0.0.1:9000;
    server 127.0.0.1:9001;
}

location ~ .php$ {
    fastcgi_pass php_backends;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

An upstream group distributes requests among the listed FastCGI servers. Adding servers does not by itself solve application-state problems. Review backend health, session affinity requirements and whether all servers share the same application files, uploads, caches and other state. If one member has a different document root or code version, requests can fail intermittently.

Buffering and timeout behavior

FastCGI settings have different scopes. Change the directive implicated by the observed symptom instead of copying arbitrary “performance” values.

Directive Current default What the setting controls When to change it
fastcgi_buffering on Whether Nginx reads the FastCGI response into buffers before sending it onward Disable only when the application genuinely requires streaming behavior
fastcgi_buffer_size and fastcgi_buffers Values depend on the Nginx build and configuration; not stated as one universal size Memory available for response buffering Adjust when headers or response chunks exceed the configured buffers
fastcgi_read_timeout 60s Maximum interval between successive reads from the FastCGI server Increase for applications that legitimately pause longer than 60 seconds between output chunks
fastcgi_connect_timeout 60s Time allowed to establish the backend connection Investigate listener reachability first; the documented practical limit is usually no more than 75 seconds
fastcgi_keep_conn off Whether Nginx keeps the FastCGI connection open after a request Set to on only when the FastCGI server and deployment support persistent connections
fastcgi_request_buffering on Whether Nginx buffers the request body before sending it upstream Disable for deliberate request streaming; once body transmission starts, retrying another server is no longer possible

Read timeout is not a total request timer

fastcgi_read_timeout 60s applies between successive reads, not to the complete response duration. An application can therefore run longer than 60 seconds if it keeps producing data within each interval. Conversely, a request that emits no data for longer than the interval can time out even if the application is still working. Set the value from the application’s actual output pattern and execution behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When buffering should remain enabled

With buffering enabled, Nginx stores response data in memory controlled by fastcgi_buffer_size and fastcgi_buffers. If the response does not fit, Nginx can write part of it to a temporary file. This is the normal behavior for ordinary dynamic pages. Turn buffering off only for an application whose protocol or user experience depends on incremental streaming, and test the resulting memory and client behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Error responses and hidden headers

fastcgi_intercept_errors is off by default. When enabled, FastCGI responses with status codes of 300 or higher can be processed by Nginx’s error_page mechanism. This is useful when the web server must present a consistent error page, but it changes where those responses are handled, so enable it intentionally.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Nginx hides the Status and X-Accel-* response headers from clients by default. Use fastcgi_pass_header only when a specific hidden field must be exposed. Do not expose internal control headers simply because an application emits them.

A systematic 502 and script-error checklist

1. Separate connection errors from script errors

A 502 generated because Nginx cannot connect to the FastCGI listener has a different remedy from “Primary script unknown.” Check the Nginx error log wording and then inspect the FastCGI service’s listener configuration. Confirm the socket exists or that the host and port accept connections from Nginx.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Check socket ownership and permissions

For a UNIX socket, verify that the Nginx worker can open it. A correct filename with restrictive ownership still produces a connection failure. Fix the service’s socket permissions or group arrangement according to your operating-system policy rather than making the socket globally writable.

3. Verify the computed script path

Logically expand $document_root$fastcgi_script_name for the failing URI and check that the resulting file exists where the FastCGI process can see it. In containerized deployments, compare mount points inside the Nginx and FastCGI environments; identical host paths are not guaranteed to be identical container paths.

4. Confirm location selection

Ensure the request actually enters the intended FastCGI location. A competing exact, prefix or regular-expression location can send the request to static-file handling or a different upstream. Review location ordering and test with a URI that should unambiguously match.

5. Check POST parameters

If GET requests succeed but POST requests fail, verify REQUEST_METHOD, CONTENT_TYPE and CONTENT_LENGTH, along with QUERY_STRING and SCRIPT_FILENAME. Missing body metadata can make an otherwise correct script appear broken.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

6. Diagnose slow responses by phase

  • Failure while opening the connection points to fastcgi_pass, listener availability or permissions.
  • Failure after connection but before the first response points to application execution or fastcgi_read_timeout.
  • Failure after periods of silence points specifically to the interval-based read timeout.
  • Large or streaming responses point to buffering choices and buffer sizes.

Adjust only the implicated setting, then retest with the same URI and workload. Raising every timeout can hide an unavailable backend without fixing it.

Deployment practices that prevent recurring failures

  • Keep the Nginx document root and the FastCGI process’s view of the application tree consistent.
  • Record the active socket or TCP endpoint as part of deployment configuration so upgrades do not leave a stale fastcgi_pass value.
  • Use a deliberately scoped PHP location instead of allowing arbitrary files to be interpreted as scripts.
  • Apply configuration changes with a syntax test before reload, and retain the previous working configuration for rollback.
  • When introducing an upstream group, verify that every backend has the same code, configuration and required shared state.
  • Set timeouts from measured application behavior and expected client interactions, not from copied values whose scope is unclear.

FastCGI proxying is therefore a translation and routing layer: Nginx chooses the endpoint, translates request information into FastCGI parameters, maps the URI to an executable script and manages the response lifecycle. Correct endpoint selection and correct path construction solve most configuration failures; buffering, timeout and scaling directives then refine behavior for the application’s actual workload.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.