现在在我的访问日志文件中logging的logging太多, – 因为图像和页面在同一个文件中。 是否有可能将所有图像移动到一个文件,只有PHP页面到第二个文件? (过滤图像和非图像文件)
server { root /home/nginx/site; index index.html index.htm index.php; access_log /home/nginx/site/_log/site_access.log; error_log /home/nginx/site/_log/site_error.log; listen 80; keepalive_timeout 70; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; } include /etc/nginx/server.conf.d/php.conf; }
access_log指令可以在不同的作用域中使用,如文档中所述:
上下文:http,服务器,位置,如果在位置,limit_except
因此,例如,可以将静态和dynamic内容的位置分开,并在需要的位置logging所需内容。
自nginx 1.7.0以来的另一种可能性是直接在access_log指令中设置条件日志logging,使用一个variables来计算不同于0的值,或者在logging必须发生时使用一个空string 。 给定$loggable这个variables的configuration示例如下所示:
access_log /path/to/access.log if=$loggable;