How to connect nginx to another remote server?

0

I hope someone can help me find the way to solve this ...

I have on a server (A) a deployment of a web application that Nginx uses to serve medium content (images, pdf, etc) and I have a server (B) that I need to serve medium content.

With which Nginx configuration directives do I connect my server (A) with (B) so that I can send the server content (B) to my web application?

PD. The folder that has the content on the server (B) is protected by username and password (I do not know where to put this data in the Nginx configuration)

    
asked by Galvatronix 12.04.2018 в 06:23
source

1 answer

0

You would need to have nginx running on both servers. Yes

  • A serves the application and
  • B serves static

What you can do is, on server A:

# las peticiones dentro del directorio 'media' se piden via proxy
location ~ ^/media/ {
    proxy_pass http://servidorB;
}

# el resto se pide normalmente
location / {
    # la cofiguración para el resto de los archivos
}

On server B it seems to me that the files should also be inside a subdirectory media .

Now, you say that to access those files you need a username and password. If we are talking about a Basic Auth (a browser dialog is opened and not a dialog in the HTML) you can send a header Authorization when doing the proxy pass.

Suppose the credentials are miuser and mipass .

Encoding the string miuser:mipass in base64 gives you bWl1c2VyOm1pcGFzcw==

console.log(btoa('miuser:mipass'));

The authentication should then send the header Authorization with the value Basic bWl1c2VyOm1pcGFzcw== .

location ~ ^/media/ {
   proxy_set_header Authorization "Basic bWl1c2VyOm1pcGFzcw=="; 
   proxy_pass http://servidorB;
}
    
answered by 12.04.2018 в 13:28