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

Francis Daly francis at
Tue Sep 1 13:56:37 UTC 2020

On Tue, Sep 01, 2020 at 08:40:02AM -0400, moyamos wrote:
> Francis Daly Wrote:
> > On Tue, Sep 01, 2020 at 01:12:03AM -0400, moyamos wrote:

Hi there,

>     location / {
>       try_files $uri $uri/ =404;
>       add_before_body /src/before_body.txt;
>       add_after_body /src/after_body.txt;
>       autoindex on;
>     }
>    location /src/ {
> #    alias /storage/path/content/;
>      proxy_pass;

That will end up with nginx requesting and

> The result is the same as my previous location. "Object Moved This document
> may be found _here_" is showing up before and after the files list. When I
> am clicking on the "_here_" link, the content is loaded correctly. But, on
> "https". There is a redirect from "http" to "https" on

That would explain the message.

Have you the option to change not to issue that redirect?

(Alternatively, you could save the content into the local files and just
serve those; but I guess you want to use the external content to stay
current when it changes.)

>    location /src/ {
>      proxy_pass;
>    }
> following errors are logged:
> 2020/09/01 16:48:41 [error] 8445#8445: *33789440 peer closed connection in
> SSL handshake (104: Connection reset by peer) while SSL handshaking to
> upstream, client: YY.YYY.YYY.YY, server:, request: "GET /
> HTTP/1.1", subrequest: "/src/after_body.txt", upstream:
> "https://XXX.XXX.XXX.XXX:443/src/after_body.txt", host: ""

That says that the nginx client and the upstream server are not able to
agree a ssl session.

Is "XXX.XXX.XXX.XXX" the same as ""? If
not, can you use "curl" or something similar to fetch
"https://XXX.XXX.XXX.XXX:443/src/after_body.txt" without errors?

Maybe you need some extra ssl config in nginx, such as and friends?

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list