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

Reinis Rozitis r at roze.lv
Tue Sep 1 13:54:06 UTC 2020


> > Now instead you want the content of the url
> > http://externalserver.com/before_body.txt?
> 
> Yes, that's right.

Can you actually open the file on the external server -  http://externalserver.com/src/before_body.txt and does it have the content you expect (without redirects)?

Note that since you have proxy_pass without the trailing slash nginx will send the request as  '/src/before_body.txt'. 

If there is no such /src/ directory on the remote server but only /before_body.txt then you have to add the slash at the end:

location /src/ {
     proxy_pass http://externalserver.com/;
}

rr



More information about the nginx mailing list