public function indexAction()
I think that this kind of http error (502 = Bad gateway) doesn't have anything to do with phalcon.
Does the application work okay if you remove the "print_r(...)" ?
Happens the same for me. It works fine if you don't access the headers...