First, I should say that this task looks rather odd to me, which might indicate that your question is an "XY Problem". Perhaps, if you would describe your original problem, we could find a better solution to it.
Now back to your question. Surprisingly, Nginx does provide some means to achieve this goal, although they are not exactly obvious. The easiest option, in my opinion, would be to use the SSI module, which comes with almost every distribution of Nginx.
The configuration in this case would look somewhat like this:
server {
...
location /log {
# Parse the contents of the response body
# as if it were an SSI template
ssi on;
# And parse it whatever the Content-Type (MIME)
# of the response body is
ssi_types *;
# Make an internal redirect to the internal
# location in order to get an SSI template
rewrite ^/log$ /log/template;
location /log/template {
# Make sure this location is not available
# from the outside world
internal;
# You can set any mime type here
default_type text/plain;
# Combine files any way you like using
# the SSI template language
return 200 '<!--# include file="/log/log1.txt" -->
<!--# include file="/log/log2.txt" -->
<!--# include file="/log/log3.txt" -->';
}
}
...
}
You can find the description and examples of SSI commands in the official documentation.
In order to achieve a better performance, it could also be a good idea to employ sendfile together with aio and tcp_nopush. This can be done by setting these directives together with ssi_min_file_chunk. Here you can read about sendfile and what it is used for.
However, even without these settings Nginx will work fast and will not eat up your memory.