开发者

NGINX route all requests for images to external server

开发者 https://www.devze.com 2023-01-19 08:01 出处:网络
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?

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 d开发者_StackOverflow社区evelopment 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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号