0

I'm trying to use proxy_pass with nginx to mask redirects to my image CDN. I'd like to be able to go to a path like:

myserver.com/images/12345/whatever-name-goes-here.jpg

I'd like that to proxy to

http://imagecdn.com/12345.jpg

i've tried the following

location ~ /images/(.*)/(.*) {
      proxy_pass http://imagecdn.com/$1.jpg; 
    }

But i keep getting 502 errors. Any idea if this is even possible ?

1 Answer 1

1

I would suggest using an actual redirect, such as:

location ~ ^/images/(.*)/(.*)$ {
    return 301 $scheme://imagecdn.com/$1.jpg;
}
Sign up to request clarification or add additional context in comments.

2 Comments

I think I see the problem, you can't use proxy_pass in this way when the location is a regex, see doc for proxy_pass and scroll down to "In some cases". You have to use a rewrite rule: location /images { rewrite ^/images/(.*)/(.*)$ $1.jpg break; proxy_pass http://imagecdn.com;}
this is the answer i was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.