Error 500: How to Troubleshoot it from Server Side (NGINX)?

“500 Internal Server ErrorA generic error message, given when an unexpected condition was encountered and no more specific message is suitable.”

If you are a PHP programmer, working with some “framework”, as minimum once time in your life, you’ve had this error. and i’m pretty sure that was very stressfull, and that you’ve felt without tools to manage this kind of problems. This is very common, but now i have a little, but huge tool that will help you in that moment.

This example is for NGINX servers over Ubuntu 16, but the same methodology works for other enviroments.

Now, let’s go to the instructions:

Open the terminal of your server

Go to directory: /var/log/nginx and view its content with ls -la

As you can see, there is an “error.log” file. You need to go inside it, and search for the last log.

sudo nano /var/log/nginx/error.log

Maybe you can use some filtering:

sudo grep "2018/04/16" /var/log/nginx/error.log
sudo grep "2018/04/16 14:" /var/log/nginx/error.log
sudo grep "2018/04/16 14:45" /var/log/nginx/error.log

#########################################################
Other Example:
1) Avoid some string:
sudo grep -v "UFW" /var/log/syslog
2) Avoid some string and filter
sudo grep -v "UFW" /var/log/syslog | grep "dockerd"
3) Avoid: UFW & level=info and level=warning
Filter dockerd
sudo grep -v "UFW" /var/log/syslog.1 | grep -v "level=info" | grep -v "level=warning" | grep "dockerd"
#########################################################

COMPRESSED FILES

Also, you can find files like error.log.2.gz (one file per day). This files are compressed, and in order to read those files, you need to use zless and zmore to read the content of the compressed files without decompressing the files

zmore

zmore is a command that is used to view the contents of a compressed file one page at a time. zmore works on files that have been compressed using “compress”, “pack” or “gzip”. As output is displayed, it pauses once the screen has become filled. To move to the next page, simply press the “Space Bar”.

zless

zless is similar to the “zmore” command, however, it displays the content of a compressed file one line at a time after the screen has become filled.

zgrep

Search compressed files for a regular expression (apply filtering)

sudo zgrep "2018/04/15 05:" /var/log/nginx/error.log.2.gz

by: Juan Pablo Donayre

Leave a Reply

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