Last active
November 7, 2015 01:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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