-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
176 lines (131 loc) · 4.18 KB
/
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# api.ctrlv.in
# api.ctrlv.vagrant
server {
listen 80;
listen [::]:80;
client_max_body_size 30m;
server_name
api.ctrlv.in
api.ctrlv.vagrant
api.vagrant.ctrlv.in;
root /var/www/ctrlv-api/public;
index index.php index.html index.htm;
include snippets/server-defaults.conf;
# Redirect to no trailing slash
#rewrite ^(.+)/$ $1 permanent;
location ~ /upload$ {
return 301 /uploader;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /assets {
include snippets/cache.conf;
}
location ~ \.php$ {
include snippets/php.conf;
}
}
# img.ctrlv.in Caching
proxy_cache_path /tmp/nginx-img-cache levels=1:2 keys_zone=ctrlvimg:60m max_size=3g inactive=168h;
proxy_temp_path /tmp/nginx-img-cache/tmp;
# img.ctrlv.in
server {
listen 80;
root /var/www/ctrlv-api/storage/img;
index index.html index.htm;
server_name img.ctrlv.in i.ctrlv.in;
location = / {
rewrite ^ http://ctrlv.in permanent;
}
location /annotations {
rewrite ^/annotations(.*)? /annotation$1 redirect;
}
location / {
# redirect .jpg requests in root to /img/blah.jpg
rewrite ^/([A-Za-z0-9_]+\.(jpg|png|gif))$ /img/$1 permanent;
#First see if the file exists locally
try_files $uri @s3;
include snippets/cache.conf;
}
location /id {
rewrite ^/id/([0-9]+)$ /display-by-id.php?imageID=$1 break;
include snippets/php.conf;
include snippets/cache.conf;
}
location ~ \.php {
include snippets/php.conf;
include snippets/cache.conf;
}
location @s3 {
#Proxy to CtrlV S3 bucket
proxy_pass http://img.ctrlv.in.s3.amazonaws.com;
#Remove Cookies (unecessary data)
proxy_set_header Cookie "";
#User's IP
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#Remove set-cookie header in response
proxy_ignore_headers Set-Cookie;
#Ignore upstream cache headers
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
#Show cache status header
add_header X-Cache-Status $upstream_cache_status;
include snippets/cache.conf;
#For updating the cache (when images are deleted)
proxy_cache_bypass $http_purge_cache;
#Save in the ctrlvimg cache
proxy_cache ctrlvimg;
proxy_cache_valid 200 30d;
proxy_cache_valid any 7d;
proxy_cache_use_stale updating;
}
}
# images on vagrant
server {
listen 80;
root /var/www/ctrlv-api//img;
index index.html index.htm;
server_name
img.vagrant.ctrlv.in
img.ctrlv.vagrant;
location / {
#First see if the file exists locally
try_files $uri @s3;
include snippets/cache.conf;
}
# FIXME!
location /id {
rewrite ^/id/([0-9]+)$ /display-by-id.php?imageID=$1 break;
include snippets/php.conf;
include snippets/cache.conf;
}
location ~ \.php {
include snippets/php.conf;
include snippets/cache.conf;
}
location @s3 {
# Proxy to CtrlV S3 bucket
#proxy_pass http://img.ctrlv.in.s3.amazonaws.com;
proxy_pass http://img.ctrlv.vagrant.s3.amazonaws.com;
# Remove Cookies (unecessary data)
proxy_set_header Cookie "";
# User's IP
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Remove set-cookie header in response
proxy_ignore_headers Set-Cookie;
# Ignore upstream cache headers
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
# Show cache status header
add_header X-Cache-Status $upstream_cache_status;
include snippets/cache.conf;
# For updating the cache (when images are deleted)
proxy_cache_bypass $http_purge_cache;
# Save in the ctrlvimg cache
proxy_cache ctrlvimg;
proxy_cache_valid 200 7d;
proxy_cache_valid any 1h;
proxy_cache_use_stale updating;
}
}