-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnginx-cdn.conf
51 lines (41 loc) · 2.01 KB
/
nginx-cdn.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# author: https://www.linkedin.com/in/abhishekdujari
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:100m max_size=1g inactive=60m;
### Explanation ###
# proxy_cache_path: where the chached files will be stored. Dont use ramdisk here, see keys_zone.
# levels: How many directories deep will the cache files be split.
# keys_zone: this is the memory space used for cache. key_zone must be unique for each host even
# though they can share the same proxy_cache_path. this uses shm internally. 1mb = 8000 cache keys
# max_size: maximum disk space for this cache. Note: YMMV.
# inactive: invalidate the cache automatically and purge regardless of freshness. YMMV
server {
listen 80;
listen [::]:80;
#edit your actual site name
server_name www.example.com;
location / {
# what is your origin IP/hostname, not your actual site but a resolver.
proxy_pass http://origin.example.com;
# what hostname does the webserver responds to.
proxy_set_header Host $host;
# if you were using Akamai, you can set a custom header to do same `True-Client-IP`
# if you used Cloudflare use CF-Connecting-IP. Some plugins and libraries recognize this header as True remote ip.
proxy_set_header True-Client-IP $remote_addr;
}
# Cache all static files, errors as well!
location ~* .(jpg|png|gif|jpeg|webp|css|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_revalidate on;
proxy_cache_valid 200 301 7d;
proxy_cache_valid 302 10s;
proxy_cache_min_uses 2;
proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Expires;
proxy_cache_valid any 30m;
proxy_set_header Host $host;
proxy_set_header True-Client-IP $remote_addr;
proxy_cache my_cache;
# You can specify an alternate origin for static files and also turn access_log off.
proxy_pass http://origin.example.com;
}
}