Nginx does not understand the PostgreSQL handshake. We had to solve this exact problem, and we open sourced the solution,
https://hub.docker.com/r/ambarltd/pgt-proxy