为什么Laravel在所有路由正常工作时仍然记录NotFoundHttpException? [英] Why Laravel still logging a NotFoundHttpException while all routes works?

查看:119
本文介绍了为什么Laravel在所有路由正常工作时仍然记录NotFoundHttpException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有已注册的路线都在工作.它们显示视图,但是在每次请求时,NotFoundHttpException都会显示在我的日志文件中.

All my registered routes are working. They display the view, yet on every request a NotFoundHttpException shows up in my log file.

我正在使用NGINX.可以是我的NGINX配置吗?

I'm using NGINX. Could it be my NGINX config?

每个请求记录的错误(即使显示了视图):

The error that is logged on every request (even though the view shows up):

log.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1429
Stack trace:
#0 /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1050): Illuminate\Routing\Router->handleRoutingException(Object(Symfony\Component\Routing\Exception\ResourceNotFoundException))
#1 /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1014): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(530): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#3 /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(506): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#4 /usr/share/nginx/www/example-staging/releases/20130815024541/content/index.php(49): Illuminate\Foundation\Application->run()
#5 {main}

NGINX配置:

# Redirect www.
server {
    listen 80;
    server_name www.example.com;
    rewrite ^(.*) http://example.com$1 permanent;
}

server {
    listen 80;
    server_name example.com;

    access_log /var/log/nginx/example.com/access.log;
    error_log /var/log/nginx/example.com/error.log;
    rewrite_log on;

    root /usr/share/nginx/www/example/current/content;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~* \.php$ {
        # Server PHP config.
        fastcgi_pass                    unix:/var/run/php5-fpm.sock;
        fastcgi_index                   index.php;
        fastcgi_split_path_info         ^(.+\.php)(.*)$;

        # Typical vars in here, nothing interesting.
        include                         /etc/nginx/fastcgi_params;
        fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    if (!-d $request_filename) {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    location ~ /\.ht {
        # (deny .htaccess)
        deny all;
    }
}

推荐答案

与NGINX配置无关.

This had nothing to with NGINX config.

收藏夹图标的路径不正确.我认为找到了所有资源,因为在Web检查器中所有状态均为OK或304.我想检查器不会在网络"标签中显示收藏夹图标.

The path to the favicon was incorrect. I assumed all resources were found because in the web inspector everything was status OK or 304. I guess the inspector doesn't show the favicon in the network tab.

正如鲁本斯·马里努佐(Rubens Mariuzzo)所述,access.log显示该网站图标的状态为500.

As Rubens Mariuzzo mentioned, the access.log revealed that the favicon was status 500.

作为一个旁注,如果您希望Laravel停止将404s/Resource Not Found作为日志文件中的错误记录下来,则可以按以下方式编辑global.php文件.

As a side note, if you would like Laravel to stop logging 404s/Resource Not Found as errors in log files, you can edit your global.php file like the following.

App::error(function(Exception $exception, $code)
{
    // Don't log 404s
    if ($exception instanceof Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
        return;
    }

    Log::error($exception);
});

这篇关于为什么Laravel在所有路由正常工作时仍然记录NotFoundHttpException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆