cancel
Showing results for 
Search instead for 
Did you mean: 

How to add/configure (redirect the request to another server) server which is not the backend?

shravanghongade
Nimbostratus
Nimbostratus

How to add/configure (redirect the request to another server) server which is not the backend?

I have configured the backend with the Nginx server as a load balancer and added two backend server instances that run fine, but now the backend servers are calling other servers but requests getting failed cause Nginx is not able to recognize the backend of backend servers.

This is below architecture.

shravanghongade_0-1655105887917.png

 

1 ACCEPTED SOLUTION

Sorry for my late reply, I was off my work and had no access to this board. 

Do you only need to proxy any of those file servers whatever backendserver was choosen or do you need to take fileserver 1 when backendserver 1 was choosen? 

Otherwise you can simply go with this, or did I missunderstood something?

 

upstream nginxlb {
server 10.3.0.7;
server 10.3.0.14 backup;
}

upstream fileservers {
server 10.3.0.20;
server 10.3.0.30 backup;
}

server {
listen 80;
server_name 10.3.0.16;
add_header Access-Control-Allow-Origin *;

location /file/path {
proxy_pass http://fileservers;
proxy_set_header Host $host;
}
location / {
proxy_pass http://nginxlb;
proxy_set_header Host $host;
}
}

 

 

View solution in original post

6 REPLIES 6

P_Kueppers
Cirrus
Cirrus

So your application running on Backend1 for example is forcing the browser to directly load files from File Server1 and this is failing cause nginx has no direct reverse proxy connection to File Server1? 

I would assume ur application is setup wrong or you need to reverseproxy the file servers as well. 

Hello @P_Kueppers 

Thank you for your quick response.

The application is designed in such a way that it connects to the FileServer directly to load the files, but the request is authorized by Backend1.

so in this scenario, I am looking to configure the FileServer as a reverse proxy. Can you please share the code snippet to configure the FileServer? I already have the load-balancer config file where I have configured the backend. Can I update the same file or do I need to create a new config file?

I think we need to clarify some things: 


@shravanghongade wrote:

 

[...] I am looking to configure the FileServer as a reverse proxy. 


You need to configure your nginx to reverse proxy the FIleServers, correct? So from the POV of nginx, the fileserver is nothing else then another "backend server". 

Yes you can just copy&paste the existing reverse proxy config from the backend servers and put that in the same file with adapted location paths. If you want you can share your acutall config file with masked/changed private informations like paths or IPs and we can take a look. 

here is the below code snippet. 

upstream nginxlb {
server 10.3.0.7;
server 10.3.0.14 backup;
}

server {
listen 80;
server_name 10.3.0.16;
add_header Access-Control-Allow-Origin *;
location / {
proxy_pass http://nginxlb;
proxy_set_header Host $host;

}
}

Sorry for my late reply, I was off my work and had no access to this board. 

Do you only need to proxy any of those file servers whatever backendserver was choosen or do you need to take fileserver 1 when backendserver 1 was choosen? 

Otherwise you can simply go with this, or did I missunderstood something?

 

upstream nginxlb {
server 10.3.0.7;
server 10.3.0.14 backup;
}

upstream fileservers {
server 10.3.0.20;
server 10.3.0.30 backup;
}

server {
listen 80;
server_name 10.3.0.16;
add_header Access-Control-Allow-Origin *;

location /file/path {
proxy_pass http://fileservers;
proxy_set_header Host $host;
}
location / {
proxy_pass http://nginxlb;
proxy_set_header Host $host;
}
}

 

 

Thank you.

It will suffice the requirements