0

I have the below configuration. Note that /images is mapped to /app/images on the destination server, and /app is left intact:

location /app {
    proxy_pass http://localhost:8080;
}
location /images {
    proxy_pass http://localhost:8080/app/images;
}

I want to use a single location:

location ~ ^/(app|images) {
    rewrite    ^/images /app/images last;
    proxy_pass http://localhost:8080;
}

But this sends a 302 to /app/images to the client in response to /images URLs. I want it to do it "internally" and just map the /images to /app/images. How is this done?

0

You need to use break so that the modified URI continues to be processed within the same location block. For example:

location ~ ^/(app|images) {
    rewrite ^/images /app$uri break;
    proxy_pass http://localhost:8080;
}

See this document for details.

2
  • Thanks. With break I still get a redirect on the client..
    – akonsu
    May 14 '17 at 16:20
  • I think we should probably append the rest of the URI. You could capture (.*) or just stick $uri after /app as shown in the updated answer. May 14 '17 at 16:33

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.