-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnginx-sample.conf
77 lines (57 loc) · 2.31 KB
/
nginx-sample.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
# This sample nginx configuration is provided as a guide. It will need to be modified for each deployment.
# It is based on our own use of Prism at Hipo serving hundreds of thousands of images per day for multiple projects.
upstream prism_servers {
server prism:3001;
}
uwsgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=prism:10m max_size=1g;
uwsgi_cache_bypass $cookie_nocache $arg_nocache $arg_force $arg_debug;
log_format access_log_format '$host - $remote_addr - $upstream_cache_status [$time_local] $request_time '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
# set loggable to 0 (false) when status is 2xx or 3xx
map $status $loggable {
~^[23] 0;
default 1;
}
server {
listen 80;
server_name default;
access_log /var/log/nginx/access.log access_log_format if=$loggable;
error_log /var/log/nginx/error.log;
uwsgi_cache prism;
# Set a webp variable to use in the cache key. It will be empty if we are not using webp, "webp" otherwise
set $webp "";
if ($http_accept ~* image/webp) {
set $webp "webp";
}
# If the 'out' arg is given then we won't force webp
if ($arg_out) {
set $webp "";
}
uwsgi_cache_key "$host$request_uri$cookie_dpr$webp";
# Access control for CORS
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "cache-control, content-range, accept, origin, session-id, content-disposition, x-requested-with, content-type, content-description, referer, user-agent";
add_header Access-Control-Allow-Credentials "true";
add_header Vary "accept";
# 10 minute pre-flight approval
add_header Access-Control-Max-Age 600;
location / {
try_files $uri @prism;
}
location @prism {
include uwsgi_params;
uwsgi_pass prism_servers;
uwsgi_read_timeout 300;
uwsgi_cache_valid 301 302 30d;
uwsgi_next_upstream error timeout http_404;
}
# Handle internal redirects to S3
# https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect
location ~* ^/s3/(.*) {
internal;
resolver 8.8.8.8;
proxy_pass https://$1;
}
}