Skip to content

Instantly share code, notes, and snippets.

@muresan
Last active November 7, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muresan/97345587c1c676cb7bc3 to your computer and use it in GitHub Desktop.
Save muresan/97345587c1c676cb7bc3 to your computer and use it in GitHub Desktop.
Pull CDN using NGINX. domain.tld.cdn.example.com/uri will be fetched from domain.tld/uri and stored in /cdn/domain.tld/uri
server {
listen 80;
server_name *.cdn.example.com;
set $origin_host 'nothing';
if ( $host ~* ([^.]+\.[^.]+)\.cdn\.example\.com$ ) {
set $origin_host $1;
}
access_log /var/log/nginx/cdn.example.com.access.log main;
location / {
root /backup/cdn/$origin_host;
error_page 404 = @fetch;
}
location @fetch {
internal;
proxy_pass http://$origin_host;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /cdn/temp;
root /cdn/$origin_host;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment