Recurring 502 Bad Gateway (nginx) and 504 Gateway Time-out (nginx) error

Hi there

Thanks to all community members for the great support provided.

I’m dealing with a Vps with Wordpress Installation, Lemp based.

Today morning my site was stocked in an 502 Bad Gateway (nginx) so I

“service ningx restarted”


“service php5-fpm restarted”


“stop: Unknown instance: php5-fpm start/running, process 1012”

So I uncommented the “# reload signal USR2” line within the php5-fpm.conf file

But I hadn’t any fortune and after 2 hours of missing attempts, I decided to reboot the droplet.

So I

“sudo shutdown -h now”

and then I switched it on by the console on

After that I could restart my php5-fpm and had my website online but the system look unstable and slow.

Connecting to the site the server gives me first 502 or 504 error. If I restart php5-fpm and nginx it looks working but if I clic again through the site it gives me again the above errors. Mmmmmmmm…

After checking web server installation, running and syntax configuration file. After checking Port, Dns and permission settings, I went through the log side of the moon.

I have to say that I found a lot of stuff but tried to move in a rational way.

first I checked the php5-fpm.log.4.gz and it gave me the following lines:

[27-Apr-2016 12:25:17] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful.

But I supposed it’s been sorted uncommenting the: “# reload signal USR2”

Then I move to the nginx dir. and I checked first the:

error.log file and I found

[notice] 25991#0: using inherited sockets from “9;”

and then the site-available.error.log.4 file and I found

2016/04/27 12:13:29 [error] 3085#0: *31943 connect() to unix:/var/run/ajenti-v-php-fcgi-ggtestit-php-fcgi-0.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client:, server: mysite, request: “POST /xmlrpc.php HTTP/1.0”, upstream: “fastcgi://unix:/var/run/ajenti-v-php-fcgi-ggtestit-php-fcgi-0.sock:”, host: “”

Sorry for the long post but I want to provided as much information as I can of an hell day.

I don’t really know where to look or what to do, so please is there anyone that can help me?

Have you any suggestion?

Thanks a lot gg

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

You can try following blog post to tune nginx Tune Nginx

I’m still trying to sort the situation? Is there someone who can help me with this? Please


Thanks for your reply

I just try with the free -m command and i get: total used free shared buffers cached Mem: 490 470 19 49 5 107 -/+ buffers/cache: 356 133 Swap: 0 0 0

That it looks I have few but still space.

About Cpu I get 05:51:42 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 05:51:42 PM all 3.77 0.01 0.29 0.11 0.00 0.01 0.00 0.00 0.00 95.81

And for Disk I/O Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn vda 6.87 99.26 51.99 4245345 2223632

avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 100.00

I have to say that it’s really hard for me to read the last two stats.

Can you help me on understand them?

Have you any further advice?