Nginx1.2.4: [warn] "log_format" directive used only on "http" level solution

Source: Internet
Author: User

After upgrading nginx to the stable version 1.2.4, you will find that the following warn is reported for the log configuration in the previous vhost/*. conf file:

Nginx: [warn] the "log_format" directive may be used only on "http" level

The Internet search solution is as follows:

Remove the following code from the server segment in/vhost/xxx. conf.

However, this will cause another problem, that is, the log files of each sub-domain name will record the logs of all requests, and the solution has not been found after a long time, after asking about Feifei, I finally found a solution.

The original log_format needs to be defined at the http layer of nginx. conf, and then you can directly reference it without defining log_format under the domain name, that is:
Add the following content to the http layer in nginx. conf:

 

The code is as follows: Copy code
Log_format Main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent' $ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for $ request_time ';

In vhost/*. conf, directly write:

The code is as follows: Copy code

Access_log./logs/blog. log Main;

However, note that the include vhost/*. conf file must be placed after log_format. Otherwise, the Main

Please refer to the following link for more information: http://wiki.nginx.org/nginxhttplogmodule?open_log_file_cache.

Solution:

Remove the following code from the server segment in/usr/local/nginx/conf/nginx. conf and put it in front of the server segment.
 

The code is as follows: Copy code

Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';

If logs are enabled on a VM, remove the server segment from the server segment and put it in front of the server segment as required.
Run the/usr/local/nginx/sbin/nginx-t command again. There is no warn warning.

The nginx prompt is obvious. It should be placed on the http layer rather than the server layer.

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.