MRatWork Forum by Mustafa Ramadhan

Sawo Project - Kloxo-MR Discussions => Kloxo-MR Bugs and Requests => Topic started by: Spacedust on 2016-12-30, 21:53:51

Title: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2016-12-30, 21:53:51
It's the 5th time already today after last update.

All pages stops responding then comes 504 error and I had to restart all web server software.

sh /script/apache-optimize --high doesn't help.

I'm running on a dedicated server with 8-core Atom and 8 GB RAM.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2016-12-31, 02:31:34
Did you run 'sh /script/cleanup'?.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2016-12-31, 03:13:30
Corrupt dababase may have the same issue. Try 'sh /script/mysql-optimize --select=repair'.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2016-12-31, 12:37:31
No errors in MySQL database. Today I got 502+504 Errors. /script/cleanup also doesn't help.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2016-12-31, 12:50:04
Ok, give me ssh and Kloxo-MR panel access. I want to know what's happens.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2016-12-31, 16:13:56
Ok, give me ssh and Kloxo-MR panel access. I want to know what's happens.

See PM. Second time today :(
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2016-12-31, 18:54:03
Didn't received in PM.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-01, 15:03:39
Please check again now ;)
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-01, 17:11:16
Read my message.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-01, 20:51:27
Just replied. That is solved now, but https in Kloxo-MR is still not working properly with:

"Unable to establish a secure connection" errors e.g. when manually generating stats.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-02, 11:19:07
It happened again today on 6:37AM - 502 error on all websites, so still not solved.

Before it happens all pages loads indefinitely and then I had to restart php-fpm.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-02, 11:45:20
I'm testing now that setting:

emergency_restart_threshold 3
emergency_restart_interval 1m
process_control_timeout 5s
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-02, 16:14:00
Now also testing this:

pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-03, 11:49:07
Still crashing with 503 errors ! Please help.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-03, 11:54:44
This seems to be an issue:

2017/01/03 09:38:01 [error] 32590#32590: *65230 limiting connections by zone "conn_limit_per_ip", client: 62.210.81.x, server: xxx.pl, request: "HEAD /test.php HTTP/2.0", host: "xxx.pl"
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-03, 12:11:46
This seems to be an issue:

2017/01/03 09:38:01 [error] 32590#32590: *65230 limiting connections by zone "conn_limit_per_ip", client: 62.210.81.90, server: xxx.pl, request: "HEAD /test.php HTTP/2.0", host: "xxx.pl"
This is to handle DDOS attack
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-03, 12:48:14
This seems to be an issue:

2017/01/03 09:38:01 [error] 32590#32590: *65230 limiting connections by zone "conn_limit_per_ip", client: 62.210.81.x, server: xxx.pl, request: "HEAD /test.php HTTP/2.0", host: "xxx.pl"
This is to handle DDOS attack

But blocks normal connections too...
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-03, 13:29:34
What's you mean 'normal connection'. They blocked external IP.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-03, 14:46:36
What's you mean 'normal connection'. They blocked external IP.

That's actually my server IP :( I use many cron jobs.

That helped a little bit, now also disabled pagespeed which is also causing stability issues.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-03, 14:54:14
What's this ?

[FastCGI: neither POLLIN nor POLLOUT...]
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-05, 00:28:33
I've downgraded from PHP 7.1.0 to 7.0.14 for testing purposes. I think it was way more stable.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-05, 16:03:33
I didn't helped. I'm testing new php config now.

Quote
pm.max_children = 64
pm.start_servers = 16
pm.min_spare_servers = 16
pm.max_spare_servers = 64
pm.max_requests = 20000
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-06, 06:42:54
Try using 'pm=dynamic' instead "pm=ondemand"
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-06, 14:45:36
Try using 'pm=dynamic' instead "pm=ondemand"

Changed that as well.

I've also disabled this - this simply doesn't work well for high-traffic websites:

Quote
#    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
#    limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=10r/s;
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 12:16:36
Still crashing !

Quote
[07-Jan-2017 04:11:07] ERROR: FPM initialization failed
[07-Jan-2017 04:11:07] ERROR: FPM initialization failed
[07-Jan-2017 04:11:07] ERROR: FPM initialization failed
[07-Jan-2017 11:31:21] ERROR: FPM initialization failed
[07-Jan-2017 11:31:30] ERROR: FPM initialization failed
[07-Jan-2017 12:10:03] ERROR: FPM initialization failed
[07-Jan-2017 12:10:03] ERROR: FPM initialization failed
[07-Jan-2017 12:10:03] ERROR: FPM initialization failed
[07-Jan-2017 12:10:03] ERROR: FPM initialization failed
[07-Jan-2017 13:10:03] ERROR: FPM initialization failed
[07-Jan-2017 13:10:03] ERROR: FPM initialization failed
[07-Jan-2017 13:10:04] ERROR: FPM initialization failed
[07-Jan-2017 13:10:04] ERROR: FPM initialization failed
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-07, 12:49:13
Try 'pkill -9 php-fpm; sh /script/restart-web'.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 13:16:36
Try 'pkill -9 php-fpm; sh /script/restart-web'.

It helps for just 20 minutes, then again pages are loading indefinitely until I restart php-fpm.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 13:28:22
I've switched from php71w to php71u. Maybe we can add remi's php71 ?
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 13:40:44
Now testing:
pm.max_children = 2
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 2
pm.max_requests = 20000
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-07, 13:49:27
Now testing:
pm.max_children = 2
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 2
pm.max_requests = 20000
Are you serious with 'pm.max_children=2'?.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 13:57:09
Now testing:
pm.max_children = 2
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 2
pm.max_requests = 20000
Are you serious with 'pm.max_children=2'?.

Sorry there is 6 out there - still freezing with no errors under minimal load ;(
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 15:05:21
Now testing this:

pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 15:21:17
Nothing helps - only php is freezing. Normal html pages works perfectly. How to debug this ?
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-07, 15:31:52
Find out log_level and change value to 'debug'.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 15:46:03
Find out log_level and change value to 'debug'.

[07-Jan-2017 16:47:02] WARNING: [pool admin] server reached pm.max_children setting (6), consider raising it

Why ???

When I got 50 in /etc/php-fpm.d/admin.conf ?

Should it be changed somewhere in /opt ?

Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-07, 16:20:02
Every each clients, you can change 'Number Of FastCGI Children' via 'limit' (or 'resouce plan') except for 'admin'.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 17:28:12
Every each clients, you can change 'Number Of FastCGI Children' via 'limit' (or 'resouce plan') except for 'admin'.

I have no clients - only admin.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-07, 17:36:22
Every each clients, you can change 'Number Of FastCGI Children' via 'limit' (or 'resouce plan') except for 'admin'.

I have no clients - only admin.
Create new client and then 'change owner' of website and mysql from 'admin' to new client. And then, to minimize memory usage for php-fpm, change 'php-ftpm type' to 'ondemand' for 'admin'.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-07, 18:03:31
Create new client and then 'change owner' of website and mysql from 'admin' to new client. And then, to minimize memory usage for php-fpm, change 'php-ftpm type' to 'ondemand' for 'admin'.
[/quote]

It seems changing in /opt/configs/php-fpm/conf/php71m/php-fpm.d/admin.conf fixed the problem.

Such config works the best:

Quote
pm = ondemand
pm.max_children = 100
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 20000
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-08, 17:52:36
Still crashing ;(

I've restored old backup from 28th of December. Maybe this will help...

It looks like these children are simply creating but not closing properly:

Quote
[08-Jan-2017 17:10:43] WARNING: [pool admin] server reached pm.max_children setting (100), consider raising it
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-08, 18:06:41
We should add:

Quote
keepalive_requests 0;

to nginx config !
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-08, 18:20:35
How much traffic your website till 100 php-fpm client is not enough?.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-08, 18:22:55
How much traffic your website till 100 php-fpm client is not enough?.

It's actually very small, but there are many search engine robots on my sites.

I got tons of such logs:

Sun Jan 08 18:21:57 2017 fastcgi:error [pid 28998] [mod_fastcgi.c(2241):] [FastCGI: neither POLLIN nor POLLOUT...] [world.domain.com]
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-08, 18:29:16
Error of 'FastCGI: neither POLLIN nor POLLOUT...' tend to meaning 'unfinish process'. DDOS attack use this 'unfinish preocess' trick.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-08, 18:32:47
Error of 'FastCGI: neither POLLIN nor POLLOUT...' tend to meaning 'unfinish process'. DDOS attack use this 'unfinish preocess' trick.

No, even single entering phpinfo page is causing this error. Something is wrong in that mod_fastcgi package. Can you check it out with PHP 7.1 ?
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: MRatWork on 2017-01-08, 20:31:02
Only found 5 times for this error in error_log file with 75KB.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-08, 21:29:28
Only found 5 times for this error in error_log file with 75KB.

So far stable ;) I'm waiting for the first crash.
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-09, 10:53:14
2 crashes during the night and all pages never loading in the morning until I restart php-fpm :(
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-09, 19:45:02
Almost stable now with these settings:

Quote
pm = dynamic
pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 500

pm.process_idle_timeout = 10s
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-09, 19:46:56
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'

Shows just 14M per each php-fpm process - so 200 children is just 2,8 GB RAM
Title: Re: nginxproxy+php-fpm crashing with 502 errors
Post by: Spacedust on 2017-01-10, 23:28:27
Allright - full stable ;D