I have no idea why in my staging server kept showing Nginx 404 Not Found where there is a crash
while locally, I can see perfectly fine
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
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.
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:
Inspections
so I think we have to check these error-prone places:
.env
to haveAPP_URL=[correct value]
&APP_DEBUG=true
&APP_ENVIOURMNT=staging
thenphp artisan config:clear
AppExceptionsHandler
redirects to an non-existing page ( outside of laravel app) :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.
Do you have anything like this in your nginx or vhost configuration?
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.