504 Gateway Timeout With Nginx And Apache

Well these couple days i spent a lot of my time debugging the nginx 504 gateway timeout error. As far as my understanding this error 504 caused by proxy timeout, or nginx wait too long for apche response. By the way i installed nginx as reverse proxy with Apache to server my static files. You can refer to my previous post: Install nginx as Reverse Proxy With Apache.

As i’m digging with Google, there are lot of possibilities of this problem. Some says because of fastcgi_read_timeout, but i’m not using fastcgi, the nginx server only serving static content. So i guess it’s not it. Then after i digging deeper, i found that my Apache causing high cpu load and memory used. Hmm… Wondering what cause this. This only happens when i post a new article in WordPress blog.

So my first guess is the Apache server still waiting for MySQL process to finish fetching the data, but it’s not finished. So the nginx keep waiting for Apache, and Apache waiting for MySQL. This process will keep loading while a new connection come, in the end it is deadlock!

Until now i’m still debugging the server, and still confuse. If you have ideas, please help me.

Comments

  1. Voku says:

    if mysql is the problem, you can check it with this command:
    -> watch -n 1 mysqladmin processlist

    • Hi Voku,
      it's been a while not hearing from you.
      Yes, i used that and found out that statpress from WordPress plugin cause the whole server slow. but i still doing the investigation. I will update my post later.

  2. Jamiedolan says:

    HI;

    Where you able to figure out what causes the 504 gateway error?

    Thanks
    Jamie

  3. Have found this is generally down to big headers being returned (are you using firebug/firephp?) alternatively its down to nginx having to wait too long for a response (ob_start in use?).

    To help with headers you can increase the size/count of the following parameters in your nginx.conf:

    client_body_buffer_size
    client_header_buffer_size
    client_max_body_size
    large_client_header_buffers
    proxy_buffers
    proxy_buffer_size

    If you're sending non-standard headers back its also worth adding:

    ignore_invalid_headers on;

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.