How do I add text to a response from a remote URL in NGINX?
Francis Daly
francis at daoine.org
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 http://externalserver.com;
That will end up with nginx requesting
http://externalserver.com/src/before_body.txt and
http://externalserver.com/src/after_body.txt
> 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 externalserver.com.
That would explain the message.
Have you the option to change externalserver.com 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 https://externalserver.com;
> }
>
> 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: test.domain.com, request: "GET /
> HTTP/1.1", subrequest: "/src/after_body.txt", upstream:
> "https://XXX.XXX.XXX.XXX:443/src/after_body.txt", host: "test.domain.com"
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 "externalserver.com"? 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
http://nginx.org/r/proxy_ssl_server_name and friends?
Good luck with it,
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list