views:

19

answers:

1

I would like to route all requests to my nginx server for jpg/png images to another external internet server which actually holds the images. What would the rewrite look like?

This is mostly for development so I'm not worried about the overhead of doing this. Then again, perhaps there is none. Both servers are mine so this isn't a request for hot-linking.

So far I have:

    # Forward requests for images to other site
    location /uploads/ {
            rewrite ^(.*)$ http://www.example.com$1 last;
    }

Which doesn't work

A: 

Actually, it was simpler than that.

rewrite ^/uploads/(.*)$  http://www.example.com/uploads/$1 last;

Or if you might have file on production OR on your development machine:

if (!-e $request_filename) {
    rewrite ^/uploads/(.*)$  http://www.example.com/uploads/$1 last;
}
Xeoncross
It will do HTTP redirect. Which may be what you want or may be not. The alternative is to proxy requests to another server, so that it looks like the images are stored at the Nginx server from the browser point of view.
Alexander Azarov
If you can post code that does that I'll up-vote several of your answers. ;)
Xeoncross