How do I add text to a response from a remote URL in NGINX?

Reinis Rozitis r at
Mon Aug 31 13:22:32 UTC 2020

> I have the following server in NGINX and it works fine. But, I am wondering is
> it possible to add text to a response from a remote URL where hosts my
> before_body.txt and after_body.txt? Is there any way to tackle this? Is it
> possible at all?

According to documentation ( add_before_body/add_after_body does a subrequest.

So something like that might work (I don't have an nginx instance with particular module compiled so you'll have to test yourself) - eg have a (internal) named location with a proxy_pass to the remote url:

location @beforebody {
    proxy_pass http://externalserver/somefile.txt;

location / {
        try_files $uri $uri/ =404;
        add_before_body @beforebody;


More information about the nginx mailing list