Nginx access log file is too large solution

Source: Internet
Author: User
This morning, a buddy ran to say that the website card was dying, and mysql often got stuck. Df-h: The partition space is full. the access log is too large, and the increase speed is quite scary. solution: Modify the nginx configuration file, access_log. Access logs only record accesses to html, images, css, js, and other files of the PHP file type. add

This morning, a buddy ran to say that the website card was dying, and mysql often got stuck.

Df-H: The partition space is full.

The access log is too large, and the increase speed is quite scary.

Solution:

Modify the nginx configuration file, access_log. Access logs are only recorded.PhpFile. Html 'target = '_ blank'>File TypeOf

Access to html, images, css, js, and other files is not recorded.

Add oneCrontabTask to regularly clear the log Content.

Specific implementation process:

1. Find the default installation path of nginx:/usr/local/nginx/

The directory contains conf logs sbin and other directories.

#Cd/Usr/local/nginx

# Cd conf/vhost // the configuration files of each site are stored in this directory

# Vim linuxso.com. conf

LoCatIon ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $

{ ExPires 30d; access_log off; // adding this line will not record these file types}

 

Location ~ . * \. (Js | css )? $ {Expires 12 h; access_log off; // records are not allowed}

 

 

Location ~ . * \. (Html | htm) $ // This part is not originally available. We only record access to the PHP file. {Access_log off;} Then, check the bottom line access_log/var/log/linuxso. log/var/www/linuxso; record/var/log/linuxso. the path where logs are stored must be followed by a regular log clearing script. After the modification is complete, run the/usr/local/nginx/sbin/nginx-s reload command to restart nginx. After the modification is completed, the log growth speed will obviously slow down, but it will continue to grow, there will also be a full day of space. 2. Write a simple script to regularly clear logs. # Vim/root/cleanlog. sh write
#/Bin/bash
/Bin/ Rm-Rf/var/log/linuxso. log
/Usr/local/nginx/sbin/nginx-s reload
# Crontab-e 0 0 ***/root/cleanlog. sh // This is cleared once every night at. Set the clearing Frequency Based on your situation.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.