It seems, that there are more things to know to address the problem. If the result is sent via ns_return, then the problem will only appear when it takes the program more than 15 secs to generate the output. In this case, this has nothing to do with NaviServer.
Maybe it is an option for you to produce streaming output (via ns_write) as soon as you have partial results available. Most proxies send the "backend unresponsive" only when they receive no upstream output after the timeout.