Nginx error log is 96GB in size

loggingnginx

Today my server was unresponsive to HTTP requests and it looks like the cause was that nginx went down because when I restarted nginx, it worked again. I wanted to take a look in the error log to see what went wrong but it's 97 gigabytes:

-rw-r----- 1 www-data adm  106614104064 Mar 23 00:52 error.log

Can anyone recommend a way to manage this kind of log? I obviously can't download it from the server and when I try to open it in nano/vi the terminal just goes unresponsive. I was thinking of also running a log parser on it and using that but I dare say that'd take a long time on a file that's almost 100 gigabytes.

Edit: After some more digging it seems the reason nginx crashed was because its log took up all available disk space, so it must've been an error that kept making nginx log to the error log, because my site doesn't get a lot of traffic.

Best Answer

You can get the last 100 lines of the log with the following command:

tail -100 error.log

Or to save them to a new file:

tail -100 error.log > error-100.log

You can save any number of lines you need instead of 100, then simply delete the original file

Moreover, to avoid such situation again you should start configuring log rotation for Nginx

Related Topic