Posted on

Have you ever get error 504 GATEWAY TIMEOUT in your site and happen all the time? One of the reason is because of the PHP-FPM children active process is full. It not able to create another process thus you get that error.

To fix this you can add more child to your PHP- FPM www.conf.

Run this command if you dont know where is your www.conf file

locate www.conf   

Edit your www.conf. You can use vi or nano. Add or edit below as your configuration. max_children is based on your RAM. If you have 5GB you need to minus with 1 for your operating system process etc. Divided by 40MB of RAM used per process.

(5 – 1 x 1024) รท 40 = 102.4

pm.max_children = 100
pm.start_servers = 25
pm.min_spare_servers = 25
pm.max_spare_servers = 35
pm.max_requests = 500

Make sure to restart the service after finish edit the file.

service php-fpm restart

One of another reason is because your SQL is not efficient and have a lot of queries. Try to fix your SQL by checking on how much time it needed to execute your queries. If you have 5 queries, total them up. It’s good for the application performance too.

If you think someone is trying to DDOS you, Fail2Ban can help you block some IP. Below are the step to configure Fail2Ban

Below are the command to install in Centos 7

yum install fail2ban fail2ban-systemd
cp -pf /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Add below config to the end of jail.local config

enabled = true
filter = nginx-req-limit
action = iptables-multiport[name=ReqLimit, port="http,https", protocol=tcp]
logpath = /var/log/nginx/*error.log
findtime = 600
bantime = 7200
maxretry = 10

Once you finish copy and edit, enabled the Fail2Ban and start the service.

service fail2ban enable
service fail2ban start
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *