3

As I am developing my project using docker, with an image that has nginx installed, if any error happens, I will only see this:

502 Bad Gateway

nginx/1.4.6 (Ubuntu)

Currently, the only way to see what's going on is checking storage/logs which is fine, but shouldn't the log error get viewed in the browser too instead of just seeing 502 Bad Gateway ?

in my .env:

APP_ENV=local
APP_DEBUG=true

Any idea?

EDIT

If there is no error in my app, I would see it normally in the browser, I just see the 502 Bad Gateway error when I have an error in Laravel app

Error would be:

[2016-02-24 11:59:38] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\Redirect' not found' in /share/app/Http/Controllers/NodesController.php:68
Stack trace:
#0 /share/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(133): Symfony\Component\Debug\Exception\FatalErrorException->__construct('', '', '', '', '', '', '', '')
#1 /share/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(118): Illuminate\Foundation\Bootstrap\HandleExceptions->fatalExceptionFromError('', '')
#2 /share/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(0): Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#3 /share/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(76): App\Http\Controllers\NodesController->store('')
#4 /share/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(76): call_user_func_array('', '')
#5 /share/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(146): Illuminate\Routing\Controller->callAction('', '')
#6 /share/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(94): Illuminate\Routing\ControllerDispatcher->call('', '', '')
#7 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}('')
#8 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func('', '')
#9 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#10 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func('', '')
#11 /share/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(96): Illuminate\Pipeline\Pipeline->then('')
#12 /share/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(54): Illuminate\Routing\ControllerDispatcher->callWithinStack('', '', '', '')
#13 /share/vendor/laravel/framework/src/Illuminate/Routing/Route.php(174): Illuminate\Routing\ControllerDispatcher->dispatch('', '', '', '')
#14 /share/vendor/laravel/framework/src/Illuminate/Routing/Route.php(140): Illuminate\Routing\Route->runController('')
#15 /share/vendor/laravel/framework/src/Illuminate/Routing/Router.php(724): Illuminate\Routing\Route->run('')
#16 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): Illuminate\Routing\Router->Illuminate\Routing\{closure}('')
#17 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func('', '')
#18 /share/app/Http/Middleware/LocaleMiddleware.php(48): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#19 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): App\Http\Middleware\LocaleMiddleware->handle('', '')
#20 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#21 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#22 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#23 /share/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#24 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle('', '')
#25 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#26 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#27 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#28 /share/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#29 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\View\Middleware\ShareErrorsFromSession->handle('', '')
#30 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#31 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#32 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#33 /share/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#34 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\Session\Middleware\StartSession->handle('', '')
#35 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#36 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#37 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#38 /share/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#39 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle('', '')
#40 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#41 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#42 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#43 /share/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#44 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\Cookie\Middleware\EncryptCookies->handle('', '')
#45 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#46 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#47 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#48 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#49 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func('', '')
#50 /share/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then('')
#51 /share/vendor/laravel/framework/src/Illuminate/Routing/Router.php(699): Illuminate\Routing\Router->runRouteWithinStack('', '')
#52 /share/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->dispatchToRoute('')
#53 /share/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(246): Illuminate\Routing\Router->dispatch('')
#54 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}('')
#55 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func('', '')
#56 /share/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#57 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Barryvdh\Debugbar\Middleware\Debugbar->handle('', '')
#58 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#59 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#60 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#61 /share/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#62 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle('', '')
#63 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array('', '')
#64 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}('')
#65 /share/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func('', '')
#66 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}('')
#67 /share/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func('', '')
#68 /share/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\Pipeline\Pipeline->then('')
#69 /share/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter('')
#70 /share/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle('')
#71 /share/public/index.php(0): {main}()
#72 {main}  

EDIT2

nginx configuration:

server {
        client_max_body_size 500M;
        listen   80 default_server;

        root /share/public/;
        index index.php index.html index.htm;

        location / {
             try_files $uri $uri/ /index.php$is_args$args;
        }

        # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                add_header Cache-Control no-cache;
        }
}
simo
  • 23,342
  • 38
  • 121
  • 218
  • What is the actual error in your laravel log? – Francesco de Guytenaere Feb 24 '16 at 12:30
  • 1
    If the error in your `/var/log/nginx/error.log` log is like: ` [error] #0: *16 upstream sent too big header while reading response header from upstream...` then perhaps [this SO answer](http://stackoverflow.com/a/27158881/2433843) could help you. – Francesco de Guytenaere Feb 24 '16 at 13:30
  • Any laravel related error, ex: [2016-02-24 11:59:38] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\Redirect' not found' in /share/app/Http/Controllers/NodesController.php:68 – simo Feb 24 '16 at 14:01
  • Alright, and what is the error in `/var/log/nginx/error.log`? – Francesco de Guytenaere Feb 24 '16 at 14:29
  • Kindly see the error above, but as I mentioned, if I fix the error, I will see my app in the browser normally, the gateway error would show only if there is an error in laravel app – simo Feb 24 '16 at 14:33
  • 1
    That's why we are curious as to the errors logged in your `/var/log/nginx/error.log` by nginx (apart from the PHP errors if they are there too.) For example `docker exec -it cat /var/log/nginx/error.log` (you can get the docker container id or name through `docker ps`) or just get into the container and view the file contents. – Francesco de Guytenaere Feb 24 '16 at 14:42

2 Answers2

2

The 502 Bad Gateway is a result of an incorrect webserver configuration. Your request is handled by Nginx and it cannot redirect it to PHP nor Laravel.

The reason for this error is most probable a missing or an incorrect proxy forward to PHP in your Nginx configuration.

These errors are only logged in the Nginx error log (/var/log/nginx/error.log) and not in the Laravel log because your app and php are not handling the request.

Luceos
  • 6,629
  • 1
  • 35
  • 65
  • 1
    Which is why I wonder about the following in the Question: `Currently, the only way to see what's going on is checking storage/logs which is fine` – Francesco de Guytenaere Feb 24 '16 at 13:18
  • 1
    @Ciccio that confused me too, however a bad gateway is never handled by PHP nor Laravel, so he will never see any registration of issues in the storage logs directory, trust me ;) – Luceos Feb 24 '16 at 13:23
  • ah, ok that makes sense. I forgot about such exceptions in the app triggering a 502. It still feels as if Nginx is configured incorrectly. What is your nginx configuration for the proxy? Can you post that @simo – Luceos Feb 24 '16 at 14:37
2

The error is happening in nginx not in PHP which is why you don't see them in the browser.

You can check the nginx logs in /var/log/nginx/ folder for errors and empty out the storage/logs folder just to be sure there are no new errors in there.

Once you fix nginx error you can configure PHP to show all errors to the browser as per https://stackoverflow.com/a/5438125/50475

Community
  • 1
  • 1
aleemb
  • 31,265
  • 19
  • 98
  • 114