On a new installation we experienced trouble where problems with images would time out. The error message suggested that there may be an infinite loop in the problem but looking at the details of the error message we saw that the message was generated by PGalias.
The actual bug was that in setting up the server, in the /etc/hosts file we had the entry
Changing this to
188.8.131.52 wwmaaserver courses1.maa.org
solved the problem.
Maybe this hint will help someone in the future.