1
votes

I've done some searching on this issue and have found other posts similar to this one, but none of the solutions have helped me.

I've got a location entry in my Nginx config which contains a proxy_pass rule, but it only seems to work when I add a trailing slash to the URL.

Here's the location stanza

    location  /webApp {
        proxy_pass         https://webapp.service.consul/webApp;
        proxy_set_header   Host webapp.service.consul;
        proxy_intercept_errors on;
    }

You can see, when I use curl and go out to /webApp/ (with trailing slash), it works fine - and the cookie is set as expected:

MacBook-Pro:~ $ curl -I https://example.com/webApp/
HTTP/1.1 302 Found
Server: nginx/1.9.11
Date: Thu, 28 Apr 2016 14:45:55 GMT
Content-Length: 0
Connection: keep-alive
Set-Cookie: JSESSIONID=440B8D729469BBD80FC92796754D9475; Path=/providerApp/; HttpOnly
Location: http://webapp.service.consul/webApp/login.do;jsessionid=440B8D729469BBD80FC92796754D9475

However, when I go out to /webApp (no trailing slash), I get a 302 Found, but I don't get redirected to the /webApp/login.do page as I did with the trailing slash:

MacBook-Pro:~$ curl -I https://example.com/webApp
HTTP/1.1 302 Found
Server: nginx/1.9.11
Date: Thu, 28 Apr 2016 14:48:44 GMT
Connection: keep-alive
Location: http://webapp.service.consul/webApp/

I have tried add a rewrite rule, something like:

rewrite ^(.*[^/])$ $1/ permanent;

But it doesn't seem to make a difference. This was working before, and I haven't really messed with this location stanza, so I'm wondering if it has something to do with one of my other locations.

Any tips?

1
I guess you should fix your consul app - Alexey Ten
@Alexey, what do you mean? The consul app works fine when adding the trailing slash (or when bypassing Nginx completely). - cookandy
This redirect issued by consul, not nginx. BTW, show full nginx's config and I can't understand is it really redirect's you to webapp.service.consul? - Alexey Ten
I think what I really want to do is redirect /webApp to /webApp/login.do on the first visit, and then send to proxy_pass. Is that possible? - cookandy

1 Answers

1
votes

You didn't actually specify IN WHICH WAY is it not working, but it sounds like an issue that should be fixable by the proxy_redirect directive.

proxy_redirect http://webapp.service.consul/webApp/ http://example.com/webApp/

(However, the best solution might be to just ensure that the hostnames are correctly specified in the rest of the configuration files.)