nginx laravel让504网关超时

I keep getting 504 gateway time out error on nginx php7.0 ubuntu 16.04 for my laravel 5.3 website.

My suspicion whereHas query is the problem. When I commented out the query, it seems working fine. the query

Item::with('image', 'brand', 'currency')->where('display', '>=', 3)->whereHas('catitems', function($query){
                $query->where('catitems.id', 5);
            })->inRandomOrder()->take(6)->get();

any idea whats wrong here?

my vultr vps spec is 1GB RAM, 1 Core.

This is the error log

recv() failed (104: Connection reset by peer) while reading response header from upstream

this is my buffer config

fastcgi_buffers 8 128k;
fastcgi_buffer_size 128k;

Any idea how to solve this?