Xeoncross
Xeoncross

Reputation: 57244

NGINX route all requests for images to external server

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

Upvotes: 2

Views: 3582

Answers (1)

Xeoncross
Xeoncross

Reputation: 57244

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;
}

Upvotes: 2

Related Questions