Nginx log filtering using ngx_log_if does not record specific logs, nginxngx_log_if

Source: Internet
Author: User
Tags nginx server

Nginx log filtering using ngx_log_if does not record specific logs, nginxngx_log_if
Ngx_log_if is a third-party module of Nginx. It is described in Github as follows: ngx_log_if is an independent module that allows you to control access logs that are not written, similar to Apache's "CustomLog env = XXX"

Step 1:
Download ngx_log_if address https://github.com/cfsego/ngx_log_if/ from Github

Step 2:
Install a third-party module to Nginx. Third-party module installation can refer to the http://wiki.nginx.org/3rdPartyModules to use -- add-module to add the unzipped ngx_log_if is as follows

./configure --add-module=/var/local/ngx_log_if-master
Then compile and install Nginx.

Step 3:
Configure access_log_bypass_if to the nginx. conf configuration file.
Server {location/{access_log_bypass_if ($ status = 404); # do not record all log information in the 404 status access_log_bypass_if ($ uri ~ * 'Images'); # do not record the log information access_log_bypass_if ($ uri = '/index.html') of all the images directories in the uri '); # Do not record the log information access_log_bypass_if ($ host ~ * 'Tonv. CC'); # do not record all logs whose host is tonv. cc }}

Restart Nginx to filter logs that do not display specific logs.
Why does nginx not record server logs?

The nginx access log is configured using the following command:
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for "'; access_log logs/access. log main; this command can appear in the http and server domains.

The error log is configured using the following command:
Error_log logs/error. log info;
By default, error_log is placed in the main domain. If you want different server domains to use their own error configurations, You need to reconfigure the error_log command in the server. When you redefine the error log, if the corresponding log level is not specified, the debug log will be blocked.
In the following example, the custom logs at the server layer shield the debugging logs of the Virtual Host:
Error_log/path/to/log debug; http {server {error_log/path/to/log ;#... #...} to avoid this problem, you can comment out this line to redefine the log configuration, or specify the debug level for the log, as shown below:
Error_log/path/to/log debug; http {server {error_log/path/to/log debug ;#...#...}
If the nginx process does not have the permission to write log information to the specified log address, nginx reports an error at startup, as shown below:

[Alert]: cocould not open error log file: open () "/path/log/nginx/error. log "failed (13: Permission denied) specific reasons for not logging also need to be analyzed according to the specific configuration file. You cannot give a definite answer because you do not know what your configuration looks like. However, based on the above analysis, you can also investigate the cause. If you have other questions, you can continue to ask.


How to store nginx server logs separately

I have always felt that nginx is still incomplete in the log direction. Currently, only some auxiliary programs can be written to separate logs.
In linux, I wrote a shell that regularly splits logs every day and sets to clear logs a few months ago.
I don't know what operating system platform you are on. You can go to Baidu to check the "nginx splitting log" and learn about it.

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.