Rt5 getmail and nginx

im strugling to get RT fully functional with email but i get different nginx errors about upstream like

upstream prematurely closed connection while reading response header from upstream quest: “POST /REST/1.0/NoAuth/mail-gateway HTTP/1.0”, upstream: “fastcgi://[::1]:5000”,
or
connect() failed (111: Connection refused) while connecting to upstream request: “POST /REST/1.0/NoAuth/mail-gateway HTTP/1.0”, upstream: “fastcgi://127.0.0.1:5000”

and sometimes mails get through to rt5 … and nginx doesnt work if i dont use localhost:5000 for passcgi if i use ip values i get 502 via browser. so i understand there are some configuration files out of order but dont know which …whole thing is behind reverse proxy and with remote mail server

Could you share how did you sort it out?