Search code examples
nginxproxyproxypass

How do you proxy a specific image with Nginx


I have this url

https://example.com/image/test.jpg

And i would like to proxy with Nginx the image at this url

https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2018/02/google-pacman-796x419.jpg

without the url changing i.e. staying the same as this https://example.com/image/test.jpg

What would you put in the location block to get this to happen?


Solution

  • You can use the proxy_pass parameter in your nginx config:

    server {
        # ...
        server_name example.com;
        # ...
    
        location /image/test.jpg {
            proxy_pass https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2018/02/google-pacman-796x419.jpg;
        }
    }