Software⏱️ 2 min read📅 2026-05-31

How to Fix: How do I prevent a Gateway Timeout with FastCGI on Nginx

Configure Nginx to increase the timeout for FastCGI requests.

Quick Answer: Use the 'fastcgi_read_timeout' and 'fastcgi_send_timeout' directives in your Nginx configuration file. Set 'fastcgi_read_timeout' to 120 seconds to prevent timeouts for API requests.

📋 Table of Contents

  1. 🔧 Solution
  2. 💡 Conclusion

To prevent Gateway Timeout with FastCGI on Nginx, you need to increase the timeout value for the location /api. By default, Nginx has a maximum timeout of 60 seconds.

🔧 Solution

Method: Increase FastCGI Timeout

  1. Step 1: Open your Nginx configuration file in a text editor.

Method: Increase FastCGI Timeout (continued)

  1. Step 2: Locate the fastcgi_param directive and add the following parameters to increase the timeout.
fastcgi_param  "script_filename" ";request_script_filename";

Method: Increase FastCGI Timeout (continued)

  1. Step 3: Save the changes and restart Nginx to apply the new configuration.

💡 Conclusion

By increasing the FastCGI timeout, you can prevent Gateway Timeout for requests to the /api location and allow for up to 120 seconds of processing time.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions