jdkealy
jdkealy

Reputation: 4907

using proxy_pass with dynamic variables nginx

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 ?

Upvotes: 0

Views: 471

Answers (1)

Faisal Memon
Faisal Memon

Reputation: 1107

I would suggest using an actual redirect, such as:

location ~ ^/images/(.*)/(.*)$ {
    return 301 $scheme://imagecdn.com/$1.jpg;
}

Upvotes: 1

Related Questions