Rewriting location directive by upstream servers

Hi,

I have two back end application servers behind nginx. The configuration
is
as follows

upstream backend1 {
server 10.1.1.11;
}
upstream backend2 {
server 10.2.2.2;
}
server {
listen 80;
server_name mysite.com;

location /appl1 {

proxy_set_header X-Real-IP $remote_addr;

    proxy_pass https://backend1/;

}
location /app2 {
proxy_pass https://backend2/;

}
}

When I access mysite.com/app1 the upstream server rewrites the url like
mysite.com/login instead of mysite.com/app1/login and the result is a
blank page.

Users are allowed either mysite.com/app1 or mysite.com/app2. In both the
cases app1 and app2 are getting rewritten with login or some other
extension. How to solve this issue.?

Regards
T

On Fri, Sep 26, 2014 at 01:20:18AM +0530, thunder hill wrote:

Hi there,

When I access mysite.com/app1 the upstream server rewrites the url like
mysite.com/login instead of mysite.com/app1/login and the result is a
blank page.

Users are allowed either mysite.com/app1 or mysite.com/app2. In both the
cases app1 and app2 are getting rewritten with login or some other
extension. How to solve this issue.?

I believe that the easiest way, if you want both to be available via
the same hostname, is to install-or-configure app1 on backend1 to be
available below the url /app1/, not below /.

And do something similar for app2.

And then remove the final “/” in your proxy_pass directives.

f

Francis D. [email protected]

Hi,

On Fri, Sep 26, 2014 at 2:35 AM, Francis D. [email protected]
wrote:

extension. How to solve this issue.?

I believe that the easiest way, if you want both to be available via
the same hostname, is to install-or-configure app1 on backend1 to be
available below the url /app1/, not below /.

And do something similar for app2.

And then remove the final “/” in your proxy_pass directives.

Thats the easiest way. Unfortunately there is no control over backend
server(s).

Just a thought:
Is there a way to keep the url mysite.com/app1 and go on with
mysite.com/app1/login. That means backend server can only rewrite the
strings after mysite.com/app1
Or are there any other ways?

Regards
T

On Fri, Sep 26, 2014 at 10:12:47AM +0530, thunder hill wrote:

On Fri, Sep 26, 2014 at 2:35 AM, Francis D. [email protected] wrote:

On Fri, Sep 26, 2014 at 01:20:18AM +0530, thunder hill wrote:

Hi there,

available below the url /app1/, not below /.
Thats the easiest way. Unfortunately there is no control over backend
server(s).

I believe the next easiest thing to do is to change the requirements,
so that users access http://app1.mysite.com or http://app2.mysite.com
instead of http://mysite.com/app1/ or http://mysite.com/app2/.

You can allow initial access to http://mysite.com/app1/, and would
issue a http redirect to http://app1.mysite.com, and have the server{}
listening for that name proxy_pass to one backend.

Just a thought:
Is there a way to keep the url mysite.com/app1 and go on with
mysite.com/app1/login. That means backend server can only rewrite the
strings after mysite.com/app1

That depends (almost) entirely on the backend; but if you do not control
it, I would be surprised if you can make it do this.

(To my mind, if you don’t control the backend, you don’t reverse proxy
to it. But that is probably not a universal opinion.)

f

Francis D. [email protected]