access_log - 如何在nginx中忽略某些php动态请求的log
阿神
阿神 2017-04-10 13:11:07
0
1
335

我的服务器是使用nginx搭建的,因为业务需要有一些请求是ajax定时刷新的,这部分请求产生的access_log对于我们来说完全是浪费空间,所以我想把它过滤掉,查了一些资料发现有这么个思路

location ^~ /index.php/test {
    access_log off;
}

因为我是用pathinfo做路由,所以rewrite以后的路径实际上这样,但是配置好以后发现,确实是不产生日志了,但是访问这个路径的php解析直接不执行了,也就是它跟我的php fastcgi配置产生了冲突

location ~ .*\.php(\/.*)*$ {
    include fastcgi.conf;
    fastcgi_param  PATH_INFO $fastcgi_script_name;
    fastcgi_pass  127.0.0.1:9000;
}

我想到了一种解决方案,那就是把动态解析的配置拷贝一份过去,比如

location ^~ /index.php/test {
    access_log off;
    include fastcgi.conf;
    fastcgi_param  PATH_INFO $fastcgi_script_name;
    fastcgi_pass  127.0.0.1:9000;
}

但是这样看起来太臃肿了,如果我要忽略多个路径,那配置文件岂不是会很长,不知道大家有什么好办法。

按Ajian说的方法配置的nginx.conf
server {
        listen       80;
        server_name  example.com www.example.com;
        root         /home/www/example/;
        index        index.html index.htm index.php;

        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }

        set $my_log /usr/local/nginx/logs/example.log;
        #if ($request_uri ~ ^/index.php/test) {
        #       set $my_log /dev/null;
        #}

        location ~ .*\.php(\/.*)*$ {
            include fastcgi.conf;
            fastcgi_param  PATH_INFO $fastcgi_script_name;
            fastcgi_pass  127.0.0.1:9000;
        }

        access_log /$my_log;
    }
阿神
阿神

闭关修行中......

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!