How do I add text to a response from a remote URL in NGINX?
    moyamos 
    nginx-forum at forum.nginx.org
       
    Tue Sep  1 12:40:02 UTC 2020
    
    
  
Francis Daly Wrote:
-------------------------------------------------------
> On Tue, Sep 01, 2020 at 01:12:03AM -0400, moyamos wrote:
> 
> Hi there,
Thanks Francis for your reply. :-)
> It looks like you had:
> 
>    location /src/ {
>        alias /storage/path/content/;
>    }
> and the url /src/before_body.txt would provide the content of the
> local
> file /storage/path/content/before_body.txt.
> 
> Now instead you want the content of the url
> http://externalserver.com/before_body.txt?
Yes, that's right.
[...]
> Can you show one complete config that does not do what you want?
server {
    listen 80;
    root /storage/path;
    index index.html;
    server_name  test.domain.com;
    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;
   }
}
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.
As soon as I am changing to 
   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"
2020/09/01 16:48:41 [error] 8445#8445: *33789440 peer closed connection in
SSL handshake (104: Connection reset by peer) while sending to client,
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"
> 
> 	f
> -- 
> Francis Daly        francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,289227,289266#msg-289266
    
    
More information about the nginx
mailing list