我在 /etc/nginx/drop.conf 中有以下 drop.conf 文件
# if you don't like seeing all the errors for missing favicon.ico requests
# sent by a lot of browsers in root we dont need to log these - they mean extra IO
location = /favicon.ico { access_log off; log_not_found off; }
# if you don't like seeing errors for a missing robots.txt in root
# same reason as above - extra IO
location = /robots.txt { allow all; access_log off; log_not_found off; }
location = /apple-touch-icon.png { access_log off; log_not_found off; }
location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; }
# this will prevent files like .htaccess .htpassword .secret .git .svn etc from being served
# You can remove the log directives if you wish to
# log any attempts at a client trying to access a hidden file
location ~ /\. { deny all; access_log off; log_not_found off; }
# Deny access to any files with a .php extension in the uploads directory
location ~* ^/wp-content/uploads/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory for multisite
location ~* /files/(.*).php$ {
deny all;
access_log off;
log_not_found off;
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我将它包含在任何服务器指令中时 - 即在我配置的任何虚拟主机中 - 我仍然在我的访问日志中获取网站图标日志。这是BUG吗??看起来包含根本不起作用?
我将其包含在以下虚拟主机示例中:
server {
listen 127.0.0.1:8080;
server_name .somehost.com;
root /var/www/somehost.com;
access_log /var/log/nginx/somehost.com-access.nginx.log main;
error_log /var/log/nginx/somehost.com-error.nginx.log;
location ~* \.php.$ {
# Proxy all requests with an URI ending with .php*
# (includes PHP, PHP3, PHP4, PHP5...)
include /etc/nginx/fastcgi.conf;
}
# all other files
location / {
root /var/www/somehost.com;
}
error_page 404 /errors/404.html;
location /errors/ {
alias /var/www/errors/;
internal;
}
#this loads custom logging configuration which disables favicon error logging
include /etc/nginx/drop.conf;
}
Run Code Online (Sandbox Code Playgroud)
但在该域的访问日志中,我仍然看到:
***** - - [06/Jul/2012:22:16:05 +0000] "GET /favicon.ico HTTP/1.1" 404 134 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11"
Run Code Online (Sandbox Code Playgroud)
是的,我已经重新启动并重新加载了 nginx。
这实际上非常有趣。当我将特定的位置指令直接添加到上面的虚拟主机并禁用包含 favicon.ico 请求时,仍然会记录。IE。我在 include 位注释并将以下内容添加到上述虚拟主机中:
#include /etc/nginx/drop.conf;
location = /favicon.ico { access_log off; log_not_found off; }
Run Code Online (Sandbox Code Playgroud)
很奇怪。