Nginx reverse proxy multi upstream (multiples sites)

Hello,

Here is my situation: I will have one frontend server running nginx, and
multiple backends servers running apache or tomcat with different
applications. I am NOT trying to do any load balancing. What I need to
do is
setup nginx to proxy connections to specific servers based on a specific
IP
of nginx.

I’m using the nginx 1.6.1.

I tried the configuration below but I have trouble with the location
configuration, I need a dynamic configuration that does not impact the
backend servers.

cat nginx.conf :
worker_processes 1;
worker_rlimit_nofile 100000;
error_log logs/error.log warn;
pid /home/nginx/logs/nginx.pid;

events {
worker_connections 10240;
use epoll;
multi_accept on;
}

http{
client_max_body_size 2048m;
include /home/nginx/naxsi/naxsi_config/naxsi_core.rules;
#include /etc/nginx/naxsi.rules;
include /home/nginx/conf/mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local]
“$request” ’
'$status $body_bytes_sent “$http_referer” ’
‘"$http_user_agent" “$http_x_forwarded_for”’;
access_log logs/access.log main;

include /home/nginx/conf/conf.d/.conf;
#include /etc/nginx/sites-enabled/
.conf;
}

cat conf.d/combined.conf :

upstream market.cloud.com {
server 10.1.0.16;
server 10.1.0.60 backup;

}


upstream panel.cloud.com {
    server 10.1.0.12;
    server 10.1.0.51 backup;

}

server {
  location / {
    proxy_pass  http://market.cloud.com;
  }
  location /panel {
    proxy_pass  http://panel.cloud.com;
  }
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257950,257950#msg-257950

On Fri, Apr 10, 2015 at 12:45:21PM -0400, cloud devops wrote:

Hi there,

Here is my situation: I will have one frontend server running nginx, and
multiple backends servers running apache or tomcat with different
applications. I am NOT trying to do any load balancing. What I need to do is
setup nginx to proxy connections to specific servers based on a specific IP
of nginx.

What request do you make that does not give the response that you want?

f

Francis D. [email protected]

When I make http://panel.cloud.com I have the first site which is on the
first stream
Si I make http://panel.cloud.com/panel, in this case it was redirected
to
the home page of the second site as the configuration is done but i can
not
navigate on the site because the URL is changed.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257950,257952#msg-257952

On Fri, Apr 10, 2015 at 05:09:33PM -0400, cloud devops wrote:

Hi there,

When I make http://panel.cloud.com I have the first site which is on the
first stream
Si I make http://panel.cloud.com/panel, in this case it was redirected to
the home page of the second site as the configuration is done but i can not
navigate on the site because the URL is changed.

I’m afraid I do not fully understand.

panel.cloud.com” resolves to your nginx machine, yes?

You do “curl -i http://panel.cloud.com/”, and you expect to get the
response from 10.1.0.16 (upstream market.cloud.com) for “/”? And that
is what you get?

You do “curl -i http://panel.cloud.com/panel”, and you expect to get
the response from 10.1.0.12 for “/panel”? What response do you get?

f

Francis D. [email protected]

On Fri, Apr 10, 2015 at 06:29:38PM -0400, cloud devops wrote:

Hi there,

Yes “market.cloud.com” and “panel.cloud.com” resolve to the nginx server.

My issue is to point the nginx server to many backend server, the nginx
requires to have different location which cause probleme to navigate in the
different backen server. Is there a solution to work with nginx as a reverse
proxy for many backend servers (differents sites)

nginx needs some way of knowing which backend server to use, for each
individual request.

The simplest is probably just to use the host in the request:

==
server {
server_name market.cloud.com;
location / {
proxy_pass http://market.cloud.com;
}
}
server {
server_name panel.cloud.com;
location / {
proxy_pass http://panel.cloud.com;
}
}

If that is not appropriate, then the next most straightforward is
probably
to change the backend servers so that all of the content on 10.1.0.12 is
available below “/panel/”, and all of the content on 10.1.0.16 is below
“/market/” (or some other unique prefix) and use that as the way that
nginx can decide which backend to use.

f

Francis D. [email protected]

Excuse me for the mail that was not clear, I don’t find the correct
technical term to use.

Yes “market.cloud.com” and “panel.cloud.com” resolve to the nginx
server.

When I do “curl -i http://panel.cloud.com/”, Iget the response from
10.1.0.16 and it work fine because it’s on the location /

When I do “curl -i http://panel.cloud.com/panel”, I get the response
from
10.1.0.12 but with /panel on the URL. So After i get the home page I
can’t
go the the other page because the URL contain the “/panel”

My issue is to point the nginx server to many backend server, the nginx
requires to have different location which cause probleme to navigate in
the
different backen server. Is there a solution to work with nginx as a
reverse
proxy for many backend servers (differents sites)

Thank you in advance

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257950,257955#msg-257955

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs