It seems to be an issue at Instagram. We have been receiving the same issue intermittently since the 3rd May. A quick search on twitter will show you that the same thing is happening to many other people around the world recently:
https://twitter.com/search?q=Instagram%20504%20gateway
The error itself is because an Instagram server not responding to the request from the load balancer or gateway (nginx in this case) in time, which leads to the gateway sending you the 504 error. This is usually caused by load on the web server or database, network routing issue or software error.
You can read the status code definitions here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Instagram will have to fix this issue, you can file a bug report here: