skip to Main Content

I have no idea why in my staging server kept showing Nginx 404 Not Found where there is a crash

enter image description here

while locally, I can see perfectly fine

enter image description here

Even if it show 404 not found, I can go to the log file in Laravel

/storage/logs/laravel-*.log

I can see the crash stack trace… I’ve tried

APP_DEBUG=true, and APP_DEBUG=false show same result

What did I forget to do?

2

Answers


  1. I believe the Nginx 404 error will raise only when nginx (or any http server) couldn’t find the page (the php page).

    usually php frameworks doesn’t allow the http servers to access each file and directory.

    and they Handle the Routing themself with their router.

    if the router couldn’t match any route, it would render the
    laravel’s 404 page

    The nginx pass all the urls to the router with the help of Url Rewrite

    Url Rewrite can be handle in apache with apache configs or .htaccess file, but in case of Nginx,

    In the case of any error in the Laravel:

    • Error or Exception would arose
    • The Laravel Exception handler catch the object.
    • it will render the view (stack trace) view

    Inspections

    so I think we have to check these error-prone places:

    1. Nginx Url Rewrite Config
    2. check the .env to have APP_URL=[correct value] & APP_DEBUG=true & APP_ENVIOURMNT=staging then php artisan config:clear
    3. check if in AppExceptionsHandler redirects to an non-existing page ( outside of laravel app) :
      • maybe something redirect to localhost & it is ok on your local, but in staging you have another domain.

    among the above, I am more suspected with the first option.

    Login or Signup to reply.
  2. Do you have anything like this in your nginx or vhost configuration?

    error_page  404              /404.html;
    error_page  500              /500.html;
    

    If so, you need to comment out this line.

    This tells nginx to serve a custom static HTML file upon HTTP 404, or 500 error. And so the error is not rendered by PHP, and by Laravel, and so no pretty error. Still, the error is thrown by PHP, so you can see it in logs.

    If you have something like this, try to comment it, reboot nginx, and try again. I think I remember having the exact same issue once, and this solved it for me.

    Note that you can have other rules like this for other HTTP codes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search