• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

nginx 504 gateway time-out

by admin

A 504 gateway time-out error occurs when Nginx cannot receive a response from the service long enough. For example from PHP-FPM.

Nginx and PHP-FPM

The most common cause of this error is the collaboration of Nginx and PHP-FPM. In case there are very slow PHP scripts, Nginx will give a 504 gateway time-out when it does not wait for an answer for 30 seconds (by default).

To get rid of this error, try raising the timeout:

location ~ \.php$ {
  fastcgi_pass unix:/tmp/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
  fastcgi_read_timeout 300;
}

Proxy

504 gateway time-out may also occur when Nginx is used as a proxy server. For example, when working with Apache. In order to avoid problems, you need to configure the timeout settings for proxy:

server {
...
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
...
}

Do not forget to restart Nginx after changing the settings:

# nginx -s reload

It is important to understand that it is highly advisable to get rid of slow scripts. A solution with timeout settings may stop working when the load increases.

Filed Under: Linux

Some more articles you might also be interested in …

  1. fuser Command Examples in Linux
  2. Linux OS Service ‘httpd’
  3. How to Change Default Port of Apache On RHEL/CentOS 7
  4. CentOS / RHEL 6 : How to rebuild Initial Ramdisk Image
  5. Understanding SELinux Booleans
  6. EFS Mount Issue “Failed to resolve server: Name or service not known”
  7. Understanding The /proc File System
  8. How to disable the default apache “Welcome Page” in CentOS/RHEL 7
  9. Encrypted vSphere vMotion
  10. How to Enable Password Aging in Linux with NIS

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright