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.