fastcgi_pass

The `fastcgi_pass` directive forwards requests to a FastCGI server for processing, typically used with PHP and other web applications.

Syntaxfastcgi_pass address;
Defaultnone
Contextlocation, if in location
Arguments1

Description

The fastcgi_pass directive in NGINX specifies the location of a FastCGI server that will handle the processing of requests. It can direct traffic to a TCP socket, a Unix socket, or an IP address with a specified port. This directive is usually configured within a location block, allowing NGINX to manage how requests are handled based on the URL path and other parameters. When a request is received, it is routed to the defined FastCGI server, which processes the request and returns the appropriate response to NGINX, which then serves it to the client.

In the usage context, you would typically set up the fastcgi_pass directive along with additional directives such as fastcgi_param, which sets parameters for the FastCGI application (like script filename, request method, etc.). The FastCGI server responds with processed data, and NGINX relays the response back to the client. This mechanism is essential for dynamic content generation in web applications, where the backend processing is offloaded to the FastCGI server to enhance performance and scalability.

Config Example

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Ensure the FastCGI server is running and reachable; otherwise, NGINX will fail to connect and respond to client requests.

Check that the socket or address specified in fastcgi_pass matches the configured port and IP address of your FastCGI application to avoid connection issues.

Make sure to include relevant parameters using fastcgi_param, especially the SCRIPT_FILENAME parameter, or the FastCGI application may not work correctly.

← Back to all directives