Need to proxypass to different servers

We have 3 servers with Nginx as webserver. The setup is as follows:

Server1 : Proxy server

Server2 : App Server1

Server3 : App Server 2

In both App servers port 80 is accessed only by Proxy server.

We need to setup in such a way that while accessing geotest.com it will
go
to proxy server and then it should proxypass to app server1 and while
accessing geotest.com/cms it should go to proxy server and then to app
server 2.

So in proxy server we need to setup as while accessing geotest.com and
all
its subdirectories like geotest.com/* it should go to app server 1
except
while accessing geotest.com/cms and its subdirectories it should go to
app
server2.

Please let us know how we can configure it.

In proxy server we setup as follows but is not working:

server {

            listen 80;

server_name geotest.com;

            location / {

                            proxy_pass  http://app1.com;

                            proxy_set_header Host      $host;

                            proxy_set_header X-Real-IP $remote_addr;

                            }

location /ui {

                            proxy_pass http://app2.com;

proxy_set_header Host $host;

                            proxy_set_header X-Real-IP $remote_addr;

                            }

            }

Can anyone please hlp us on it.

Thanks

Geo

On Tue, Mar 19, 2013 at 09:25:09AM +0530, Geo P.C. wrote:

Hi there,

We have 3 servers with Nginx as webserver. The setup is as follows:

So in proxy server we need to setup as while accessing geotest.com and all
its subdirectories like geotest.com/* it should go to app server 1 except
while accessing geotest.com/cms and its subdirectories it should go to app
server2.

Please let us know how we can configure it.

“location /cms” should have “proxy_pass” to app2, “location /” should
have
“proxy_pass” to app1. Almost exactly as you show. Except that you spell
“cms” “ui”, for some reason.

In proxy server we setup as follows but is not working:

Be specific.

What one request do you make that does not give the response that you
expect? What response do you get instead?

Other things: you must set the world up so that the browser actually
gets to your proxy server when requesting geotest.com. That’s outside
of anything nginx can do.

You must set things up so that nginx actually gets to your app2 server
when…

                            proxy_pass http://app2.com;

…using the name app2.com. That needs a working resolver, or a
configured
upstream block. Or just use the IP address directly here.

And you will probably want to make sure that everything on app2 knows
that it is effectively being served below /cms, as otherwise any links
to other resources on that server may not work as you want.

(And note that “location /cms” and “location /cms/” do different things,
and may not both be what you want.)

f

Francis D. [email protected]

Thanks for your reply. Please see this:

In Proxy server we have the setup as follows:

server {

listen 80;

             server_name geotest.com;

             proxy_buffering on;

proxy_redirect off;

            proxy_set_header   Host             $host;

            proxy_set_header   X-Real-IP        $remote_addr;

             proxy_set_header   X-Forwarded-For

$proxy_add_x_forwarded_for;

location / {

                            proxy_pass       http://192.168.0.1/; 

#app1
server

}

location /cms {

                            proxy_pass       http://192.168.0.2/; 

app2 server

}

}

Now while accessing the url the result are as follows:

  1.   geotest.com  Working fine getting the contents of app1 server
    
  2.   geotest.com/a1  Working fine getting the contents of app1 
    

server

  1.   geotest.com/cms  Not working. Site proxypass to app2 server but
    

we are getting a 404 page.

  1.   geotest.com/cmsssss Same as above result.
    

For your information the cms application running app2 server is graphite
server and you can find the nginx configuration file from the url:
Graphite and Nginx – frl1nuX in which we use the server name as
geotest.com

So can you please help us on it.

Thanks

Geo

On Tue, Mar 19, 2013 at 07:42:25PM +0530, Geo P.C. wrote:

Hi there,

location / {
proxy_pass http://192.168.0.1/; #app1
}

location /cms {
proxy_pass http://192.168.0.2/; #
}

  1.   geotest.com  Working fine getting the contents of app1 server
    
  2.   geotest.com/a1  Working fine getting the contents of app1 server
    

So far, so good.

  1.   geotest.com/cms  Not working. Site proxypass to app2 server but
    

we are getting a 404 page.

What request do you want nginx to make of the app2 server here? – /,
/cms, or something else?

What request is nginx making of the app2 server? – check the app2
server
logs, if the nginx logs don’t tell you.

If you make either of those requests of app2 yourself (using curl),
do you get what you expect?

  1.   geotest.com/cmsssss Same as above result.
    

Same questions. What do you want to happen? What does happen?

For your information the cms application running app2 server is graphite
server and you can find the nginx configuration file from the url:
Graphite and Nginx – frl1nuX in which we use the server name as geotest.com

Unless graphite is one of those special and beautiful apps that allow
themselves to be easily reverse-proxied at a non-root url, you may end
up happier if you just use two separate server{} blocks with different
server_name directives.

But that can be worried about after you see how your /cms locations
work.

f

Francis D. [email protected]

On Mar 19, 2013, at 18:41 , Andreas Weber wrote:

Im not expert but i think you must specify /cms BEFORE / because “/” will match
everything

No. Since “/” and “/cms” are not regex locations, nginx finds the
maximum match despite
location order. This is why using only non-regex locations allows to
create at once large and
easy to maintain configurations with a lot of locations.

Hi,

Im not expert but i think you must specify /cms BEFORE / because “/”
will
match everything

best regards

andreas

Threepwood: Ha-ha! Taste cold steel, feeble cannon restraint rope!

2013/3/19 Geo P.C. [email protected]

Thanks for your updates. We are able to proxypass to another domain. But
the issue is domains sub directories are not working fine.

That is in

server {

            listen 80;

server_name geotest.com;

proxy_set_header Host geotest.com;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            location / {

                            proxy_pass  http://192.168.1.1;

                               }

location /cms {

                            proxy_pass http://192.168.1.2;

                            }

            }

While accessing geotest.com/cms we are getting the application that
running
on 192.168.1.2 but when we access geotest.com/cms/address we are not
getting the address page but insated we are getting the same index page.

Thats we are unable to access any subdirectories inside /cms/ if we
access
we are getting the index page only.

So can you please guys help us on it.

Thanks

Geo

On Thu, 2013-03-21 at 01:48 -0400, geopcgeo wrote:

location / {

Posted at Nginx Forum:
Re: Need to proxypass to different servers.
location ^~ /cms {
}

??

We also tried these options:

location ^~ /cms {
}

location ^~ /cms/ {
}

But still gets same issue. We are only getting the index page.

Posted at Nginx Forum:

Thanks for your updates. We are able to proxypass to another domain. But
the issue is domain’s sub directories are not working fine.
That is in

server {
listen 80;
server_name geotest.com;
proxy_set_header Host geotest.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://192.168.1.1;
}
location /cms {
proxy_pass http://192.168.1.2;
}
}

While accessing geotest.com/cms we are getting the application that
running
on 192.168.1.2 but when we access geotest.com/cms/address we are not
getting the address page but insated we are getting the same index page.

That’s we are unable to access any subdirectories inside /cms/ if we
access
we are getting the index page only.

So can you please guys help us on it.

Thanks

Geo

Posted at Nginx Forum:

On Thu, Mar 21, 2013 at 01:48:20AM -0400, geopcgeo wrote:

Hi there,

Thanks for your updates. We are able to proxypass to another domain. But
the issue is domain’s sub directories are not working fine.

So, when you do

curl -i http://geotest.com/cms/address

what response do you get? What response do you want to get?

What request was actually made to the server on 192.168.1.2?

What do you get if you make that request yourself with curl?

f

Francis D. [email protected]