Seeing the “503 Service Temporarily Unavailable” error on your NGINX-powered website can be frustrating. But don’t worry; some methods exist to troubleshoot and fix this issue. In this guide, I will help you solve this issue easily.
Why 503 Service Unavailable Error?
A 503 error usually means the server is temporarily unable to handle the request. It’s like the website’s office is closed, even though it should be open. Often, it occurs because the server is overloaded or the back-end service (like PHP or a database) isn’t running correctly.
Check If PHP-FPM Is Running
If your site runs on PHP, first see if PHP-FPM is even up. To do it, open a terminal and run the command:
sudo systemctl status php-fpm
(If you’re using a specific version, like PHP 7.4, try sudo systemctl status php7.4-fpm
instead.)
If PHP-FPM is dead or inactive, bring it back to life with: sudo systemctl start php-fpm
If it doesn’t start up, the logs can be your best friend. Check: /var/log/php-fpm/
Try Restarting NGINX and PHP-FPM
Sometimes, turning things off and on again really does work!. Then try running the following commands:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
This will reset connections and clear up temporary hiccups.
Check if your server is overloaded
Use commands like top or htop to see what’s eating up your resources. If a process is hogging everything, it might be time to optimize your setup or add caching.
top
htop
Also read: https://www.veeble.com/kb/linux-memory-monitoring-optimization-commands/ for references.
"If resource constraints keep causing you problems, a VPS or cloud plan from Veeble can offer the extra RAM and CPU power you need to handle more traffic smoothly."
Check Out the Logs
Logs are like the black box of your server. They hold clues about what went wrong. To find the clues, check out the error log files:
NGINX error logs: /var/log/nginx/error.log
PHP-FPM error logs: /var/log/php-fpm/error.log
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/php-fpm/error.log
The above commands read out the errors and give a clue on how to resolve the issue. Watch out for “upstream” errors, which often mean PHP-FPM isn’t working right in /var/log/php-fpm/error.log
Double-Check Your NGINX Config
Sometimes, a tiny typo in your configuration can bring down the whole show. To check it, execute the below command:
sudo nginx -t
If there are errors, fix them first and reload NGINX with the below command:
sudo systemctl reload nginx
Tweak PHP-FPM Settings
If your server is under heavy load, you might need to adjust PHP-FPM settings. The config file is usually at /etc/php/7.4/fpm/pool.d/www.conf
Try tweaking the following values and see if it resolves after tweaking it.
pm.max_children
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
A NGINX 503 Service Temporarily Unavailable error doesn’t have to ruin your day. With a bit of troubleshooting, you can get your site back online. Hosting providers like Veeble offer monitoring and tuning options that can keep your server optimized, even during heavy traffic. This way, you won’t have to troubleshoot on your own when things get too busy!