Which comes back to my question. Can one do that with apache and nginx? I'm pretty sure I've seen methods for this in Apache but only the paid version of nginx. Am I wrong?
Today, app servers are mostly separated from front-end servers because, it turns out, it's best to not hold on to too much memory and/or threads while waiting for a slow client to receive their stuff. So async servers like Nginx are used on the front tier and they knock to app servers over the net.
But Nginx does have a Lua module, and, I think, Perl. Afaik both are in the free version. Mostly used to augment configuration, or for lightweight interfacing directly with databases (ahem Redis and Memcached cough).
I mentioned Apache modules in my comment. Write a module, add it to Apache’s config, your code loads with the web server.
Looks like one can also write nginx modules, but I’m not familiar with nginx licensing to know if a purchase is required to use that in a commercial deployment.
It's not required, and in fact there's a big open source project taking advantage of that: OpenResty uses a module that loads LuaJIT into Nginx, and builds very fast applications into Nginx using Lua.