nginx proxy_pass with url rewrite - preserve URL

1.7k views Asked by At

I am trying to rewrite url for another domain, main agenda is keep the user in same URL[dev.gworks.mobi].

http://dev.gworks.mobi/openam/* -> http://frock.gworks.mobi:8080/openam/*

location /openam {

          proxy_pass http://frock.gworks.mobi:8080/;
          proxy_redirect     off;
          proxy_set_header Host $host;
}

it partially works

  1. http://dev.gworks.mobi/openam/ -> http://frock.gworks.mobi:8080/ [it works]
  2. http://dev.gworks.mobi/openam/XUI/#login/ -> http://frock.gworks.mobi:8080/openam/XUI/#login/[it does not work]

The reason is http://dev.gworks.mobi/openam/XUI/#login/ proxy to http://frock.gworks.mobi:8080//XUI/#login/ instead of http://frock.gworks.mobi:8080/openam/XUI/#login/. I'm trying rewrite URL but I'm not successful.

rewrite ^/openam/(.*)$ /$1 last;

can anyone help me to achieve my use case?

1

There are 1 answers

0
Bilal Usean On

Below one is works

location /openam {
            proxy_pass http://frock.gworks.mobi:8080/openam;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_buffering off;
}