Skip to content

Instantly share code, notes, and snippets.

@chenset
Last active August 14, 2022 05:24
Show Gist options
  • Save chenset/62ffe12e9c6f038e54e8685d7e2099c1 to your computer and use it in GitHub Desktop.
Save chenset/62ffe12e9c6f038e54e8685d7e2099c1 to your computer and use it in GitHub Desktop.
Proxy image with nginx
server {
listen 80;
server_name domain.com;
merge_slashes off;
location ~ /(?<r>http://.*) {
resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
proxy_set_header Referer "";
proxy_pass $r;
expires 10y;
}
location ~ /(?<r>https://.*) {
resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
proxy_set_header Referer "";
proxy_pass $r;
expires 10y;
}
}
# https://www.nginx.com/blog/nginx-caching-guide/
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:100m max_size=10g inactive=7d use_temp_path=off;
server {
listen 80;
server_name domain.com;
merge_slashes off;
location ~ /(?<r>http://.*) {
proxy_cache my_cache;
resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
proxy_set_header Referer "";
proxy_pass $r;
expires 10y;
}
location ~ /(?<r>https://.*) {
proxy_cache my_cache;
resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
proxy_set_header Referer "";
proxy_pass $r;
expires 10y;
}
}
@chenset
Copy link
Author

chenset commented Feb 13, 2019

How can I use:

http://domain.com/https://img1.url.com/image.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment