Some pages when trying to load I receive a Bad Gateway Ngnix 502 error however upon page refresh it will resolve the page load. Not sure if this is associated however one page requires a heavy mssql query and the page will load with the result however will not continue to load CSS associated to the page.
master.blade.php file contains the bootstrap css and theme styling, extention.blade.php will extend the master (as with multiple other pages on my project) however it includes a DB query which successfully returns when dd() however fails to load the css. Other pages sometimes have this issue and multiple refresh will correct the page load.
Hope someone can help my situation. Sounds like a configuration issue? Just not sure..
UPDATE
All pages experience first a Bad Gateway 502 followed by a refresh of loss of CSS (bootstrap mainly). The Bad Gateway will come after 2 or 3 browser refresh on static pages with no association to DB queries.
My Setup:
- Mac OS X Sierra 10.12.6
- PHP 7.1
- Nginx and Laravel 5.6
www.conf setup:
- pm = dynamic
- pm.max_children = 10
- pm.start_servers = 10
- pm.min_spare_servers = 10
- pm.max_spare_servers = 10
~/.valet/Nginx/Sites.dev-env (my projects directory where Valet is parked) has the following lines (added by myself to try and resolve this issue):
`fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/Users/myusername/.valet/valet.sock;
fastcgi_index
/Users/myusername/.composer/vendor/laravel/valet/server.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
/Users/myusername/.composer/vendor/laravel/valet/server.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;`
php-fpm.conf setup:
- Default with
include=/usr/local/etc/php/7.1/php-fpm.d/*.conf
Laravel Storage has a 777 permission set (just to determine if its a file permission issue, this will be reverted back to 755 fyi)
Now the key to solving this issue is the error logs which provide the following:
php error log:
`[22-Feb-2018 10:29:06 Australia/Sydney] PHP Fatal error: Uncaught
PDOException: SQLSTATE[25000]: [FreeTDS][SQL Server]The ROLLBACK
TRANSACTION request has no corresp$
Stack trace:
0 {main}
thrown in [no active file] on line 0`
However, the only SQL I have related to this is a select query but I don't believe this is the main cause of the Bad Gateway.
~/.valet/log/nginx-error.log:
`2018/02/22 10:24:23 [error] 62179#0: *9 upstream prematurely closed
connection while reading response header from upstream, client:
127.0.0.1, server: sites.dev-env`
This I believe is the main issue. It occurs at every point of a Bad Gateway error and I am stuck trying to work out what exactly it means. This log file has a ton of these errors obviously me trying to work out what the. is going on.
How I resolve the issue temporarily is by doing a valet restart. A Brew restart of nginx or php doesn't resolve the issue, therefore, isolating this to valet.