全局禁用Nginx中所有站点的静态内容访问日志logging

我试图全局禁用access_log和log_not_found所有静态内容和所有运行在同一个nginx实例上的虚拟主机

为了pipe理服务器块中的全局设置,我在每个虚拟主机的服务器块中都包含一个global/restrictions.conf

虚拟主机的configuration如下所示:

 server { listen 1.2.3.4:80; server_name domain.com *.domain.com; access_log /var/domains/domain.com-access.log combined; error_log /var/domains/domain.com-error.log error; root /var/www/domain.com/; location / { index index.php index.html index.htm; try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^ /index.php last; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/domain.com-php-fpm.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } # Include global restrictions config include global/restrictions.conf; } 

global / restrictions.conf中所有虚拟主机的全局configuration文件如下所示:

 # Global restrictions configuration file. # Will be included in the server {] block of each vhost. # Disable logging for robots.txt files <--- WORKS location = /robots.txt { allow all; log_not_found off; access_log off; } # Disable logging for all static files <--- DOES NOT WORK (WHY??) location ~ \.(atom|bmp|bz2|css|doc|docx|eot|exe|gif|gz|ico|jpeg|jpg|js|mid|midi|mp4|ogg|ogv|otf|png|ppt|rar|rss|rtf|svg|svgz|swf|tar|tgz|ttf|txt|wav|woff|xml|xls|xlsx|zip)$ { log_not_found off; access_log off; } 

robots.txt的规则似乎在所有的虚拟主机上工作正常,但不知何故规则与所有其他静态文件的正则expression式将无法正常工作,我似乎无法弄清楚为什么。

任何想法或build议?

通过replacelocation ~ \.修复它location ~ \.location ~* ^.+.

正则expression式引起了这个问题。