• 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. CentOS / RHEL 6 : How to force a NTP sync with the NTP server(s)
  2. ping not working on a Newly Built CentOS/RHEL server
  3. How to find which specific ethernet device corresponds to a specific port on a multi-interface network card in CentOS/RHEL
  4. CentOS / RHEL : How to migrate storage (LVM) with pvmove Command
  5. legit Command Examples in Linux
  6. /var/cache/yum Constantly Filling Files System in CentOS/RHEL
  7. aptitude Command Examples in Linux
  8. addr2line: command not found
  9. pvcreate error : Can’t open /dev/sdx exclusively. Mounted filesystem?
  10. How to analyze basic system performance using – vmstat, sar, iostat and mpstat

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright