1

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.

2 Answers 2

2

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

1
  • Without using an additional external program and custom script, nginx access.log rotation is easy but not so for error.log.
    – Ed Randall
    Commented Jun 26, 2018 at 7:38
0

I'd suggest truncating the file with : > /path/to/error.log. That will zero the file and you won't have to restart your nginx. From there, you can run tail -f /path/to/error.log to see why it's growing at such an accelerated rate.

1
  • 1
    Truncating a file with such big size ain't a good idea, it will kill the performance. Deleting the file then telling Nginx to re-read its logs files by sending a kill -USR1 to the master process would be the solution to go with to avoid Nginx restarting
    – minniux
    Commented Mar 23, 2013 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .