503 Service Unavailable

Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request.

Are you getting a 503 HTTP error on your site? Most of the times this is caused by one of the following:

1. The server is hitting the value for MaxRequestWorkers 

To find out if this is the cause, search the Apache web server logs as:

# grep MaxRequestWorkers /usr/local/apache/logs/error_log
root@web [~]# grep MaxRequestWorkers /usr/local/apache/logs/error_log
[Mon Apr 27 20:26:33.636250 2020] [mpm_prefork:error] [pid 19097] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Fri May 01 13:15:05.675348 2020] [mpm_prefork:error] [pid 21866] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Thu May 07 08:36:12.913913 2020] [mpm_prefork:error] [pid 14657] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
root@web [~]# 

To find out the value for the MaxRequestWorkers parameter, use

# grep MaxRequestWorkers /usr/local/apache/conf/httpd.conf
root@web [~]# grep MaxRequestWorkers /usr/local/apache/conf/httpd.conf
MaxRequestWorkers 160
root@web [~]#

Adjust this value per your needs.


2. The value for MariaDB/MySQL max_connections is being reached.

Find out the max_connections value from the MySQL server configuration file:

# cat /etc/my.cnf | grep "max_conn"
root@web [~]# cat /etc/my.cnf | grep "max_conn"
max_conections=100
root@web [~]#

To find out if this value was reached, use:

root@web [~]# mysql -e "show global status where variable_name like 'Max%used%connections'"
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 50    |
+----------------------+-------+
root@web [~]#

To combine the previous two commands in one:

# cat /etc/my.cnf | grep "max_conn";mysql -e "show global status where variable_name like 'Max%used%connections'"

3. The server is running out of memory (OOM).

You can find if this is the case by running commands like

# journalctl -b | grep "code=killed"

This will search the logs and list the OOMs when processes were killed:

root@web [~]# journalctl -b | grep "code=killed"
May 12 02:51:02 web.plothost.com systemd[1]: lfd.service: main process exited, code=killed, status=9/KILL
root@web [~]#

This Post Has 2 Comments

  1. somas

    Thanks, this is what I was looking for in the last hours. THanks.

    1. Max

      Thanks for the comment 🙂

Leave a Reply