The log settings of Nginx under the Linux system

Source: Internet
Author: User

(All CentOS system commands in this article are represented by a bold slash, which is easy for you to read)


I think a lot of people, like me, in the first contact with Linux, from the bottom of my heart is very offensive, obviously put windows so the system does not need, but to engage in this black system interface, always feel that there is a return to Dos feeling. And most importantly, the configuration of Windows is in the software interface, the configuration of the place to click the mouse or select the address bar, etc., it is easier to get started. and the Windows editing interface support CTRL + Z this undo command, if some configuration accidentally touched by themselves, as long as the interface is not the big deal on the CTRL + Z can be restored to the original appearance, can not progress we can at least remain unchanged. And the reverse operation of the Linux command is basically no, the command line interface of the file deleted then deleted, the file MV to their own memory of the place, once the history can not find this command, the basic could not rescue, so the operation of the environment will inevitably always give people a way to walk on the feeling.


By the Way,shell of the reverse operation although basically not, but vim of the inverse operation is still there. ESC after pressing U, you can undo an operation, as long as not close and save, press u can always press to the initial state of the file, if you want to undo things with U back, then ctrl+r.


To return, this time the content is all configuration, is still a variety of nginx basic configuration, and basically are operating under the VIM, once the initial. conf file changed, you back to the original appearance.

Log configuration

Log is a very important thing, maintenance personnel to the log to reverse the previous operation, and necessary to the log file output. Nginx Log configuration path or in the Nginx file under the/conf/nginx.conf file, vim a bit. Then locate the Log-format line.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/79/C0/wKiom1aaVO2gRkFJAABQmrFpph0899.png "title=" Screenshot.png "alt=" Wkiom1aavo2grkfjaabqmrfpph0899.png "/>

Red content is the log configuration, the above server_token is a security token, to prevent the robot brush requirements, here is the meaning of each of the Log_format:

$remote _ADDR: The address of the client

$remote _user[$time _local]: The name of the client [local time]

$request: The URL requested by the client

$status: Request Status

$body _bytes_sent: The number of bytes sent to the client

$http _refere: The original page, that is, the client is from that page here

$http _user_agent: Browser Information for clients

$http _x_forward_for: IP address of the client

Access_log off: The current logging function is not open and can be changed to ON.


Log file data is recorded in the Order of the red box, it can be said that the client's operation will be recorded by the log file, but in this case, the log files will be more and more backlog, resulting in a difficult query, it is necessary to automatically cut log files.

If you want to say that every day of the 23:59 want to cut the log file, that day's log to save the date name, and then open a new log file to save a new day log. So we have to create a batch file in the/logs/directory, called Cutlog.sh, and then vim it, for editing,

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/79/C0/wKioL1aaYOmzH5htAABMOUrfi7s279.png "title=" Screenshot-1.png "alt=" wkiol1aayomzh5htaabmourfi7s279.png "/> Then exits back to the log directory,#crontab-E.

But if you have not used crontab before, the system will error, prompting Crontab:command not found, but #man crontab, but there are results. Here we need to install the Crond module.

#yum-install-y Vixie-cron

At this point the installation process occurs, after the installation is complete,#chkconfig--list crond, detect whether the boot is started, and then in the #service crond start. So you can use crontab.

#crontab-E, a shell will appear, we enter "/bin/bash/usr/local/nginx/logs/cutlog.sh", and then save the exit, the system will confirm the time format, if the time format is not correct, You will be prompted not to establish the relevant file. We press N on the line and press Y to return to the edit.


At this point, the process of automatically cutting log files is over, and the effect is to generate a day-by-day file named after the/usr/local/nginx/logs/cutlog.sh path to record the server's logs.

This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1735704

The log settings of Nginx under the Linux system

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.