0

I have the following nginx rule

    server_name mydomain.com;

    location ^~ /geosamples/ {
       rewrite  ^/geosamples/(.*)$  /geoserver/$1  break;
       proxy_pass http://192.168.92.100:8088;
       proxy_connect_timeout 180s;
       proxy_read_timeout 240s;
    }

If I access the application at mydomain.com/geosamples/index.html it works fine.

If I access it at

mydomain.com/geosamples/

it gets redirected to

mydomain.com/geoserver/index.html

and obviously doesn't work anymore!

I am guessing the geoserver app is redirecting the client to this buggy URL...

How can I prevent this? I would appreciate any help!

2 Answers 2

0

You need to add a proxy_redirect directive to reverse your rewrite when the upstream server returns a 3xx response.

Try:

proxy_redirect http://example.com/geoserver/ http://example.com/geosamples/;

See this document for the details.

2
  • Thanks, I did the following but no luck proxy_redirect example.com/geoserver example.com/geosamples;
    – Thomas
    Oct 13, 2016 at 20:17
  • 1
    The proxy_redirect needs to match the Location header in the 3xx response. Use a browser plug-in to analyse the exact response coming from your server, so that you can make sure that the proxy_redirect contains the correct value. Oct 13, 2016 at 20:28
0

You just don't need to overcomplicate things.

location ^~ /geosamples/ {
   proxy_pass http://192.168.92.100:8088/geoserver/;
   proxy_connect_timeout 180s;
   proxy_read_timeout 240s;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.