-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmb-nginx.conf
84 lines (72 loc) · 2.51 KB
/
tmb-nginx.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
server {
listen 80;
server_name tmb.rating-widget.com;
root /full/path/to/your/app/thumb;
location = / {
set $src_filename_l _;
set $src_filename_r _;
set $src_extension _;
#
# Parse src param that have a valid image extension (jpg, jpeg, png or gif).
#
if ($args ~ "src=http(s?)%3A%2F%2F(?<src_filename_l>.{3,115})(.*?)(?<src_filename_r>.{0,115})\.(?<src_extension>(jpg|gif|png|jpeg))$"){ }
#
# Parse src param with a general address (image or any other given url).
#
if ($args ~ "src=http(s?)%3A%2F%2F(?<src_address_l>.{3,115})(.*?)(?<src_address_r>.{0,115})$"){ }
#
# If the src param was NOT a valid image url - use general address and set the file extension to jpg by default.
#
if ($src_extension = "_") {
set $src_filename_l $src_address_l;
set $src_filename_r $src_address_r;
set $src_extension jpg;
}
#
# Set some default values for timthumb width, height and zoom crop.
#
set $zc 1;
set $w 152;
set $h 110;
if ($arg_zc) {
set $zc $arg_zc;
}
if ($arg_w) {
set $w $arg_w;
}
if ($arg_h) {
set $h $arg_h;
}
#
# Finally, combine the cache filename.
#
set $os_filename "$src_filename_l$src_filename_r-$zc-$h-$w.$src_extension";
#
# If the file found on the disk, simply serve the cached file without starting php-fpm.
#
if (-f $document_root/img-cache/$os_filename) {
rewrite ^ /img-cache/$os_filename last;
return 200;
}
include fastcgi_params;
fastcgi_read_timeout 120s;
fastcgi_index timthumb.php;
# Optional addition of the filename for DEBUG.
fastcgi_param QUERY_STRING $query_string&p=$os_filename;
fastcgi_param SCRIPT_FILENAME $document_root/timthumb.php;
#
# If the file is not found on the disk route the request to timthumb php script.
#
if (!-f $document_root/img-cache/$os_filename) {
fastcgi_pass unix:/tmp/php5-fpm.sock;
}
}
#
# Cache all requests
#
add_header Cache-Control public;
add_header Cache-Control must-revalidate;
expires max;
include /etc/nginx/conf.global.d/restrictions.conf;
include /etc/nginx/conf.global.d/common.conf;
}