forked from WordPress/openverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf.template
88 lines (75 loc) · 2.54 KB
/
nginx.conf.template
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
# The following variables are substituted into the environment using envsubst.
# This occurs automatically as part of the nginx image startup.
# See: https://github.com/nginxinc/docker-nginx/blob/456bf337ceb922a207651aa7c6077a316c3e368c/entrypoint/20-envsubst-on-templates.sh#L17
# - DJANGO_NGINX_UPSTREAM_URL
# - DJANGO_NGINX_GIT_REVISION
# - DJANGO_NGINX_ENVIRONMENT
error_log /var/log/nginx/error.log;
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"host_header": "$host",'
'"body_bytes_sent":$body_bytes_sent,'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"upstream_response_time":$upstream_response_time,'
'"http_x_forwarded_for":"$http_x_forwarded_for"'
'}';
access_log /var/log/nginx/access.log json_combined;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
# Compress large responses to save bandwidth and improve latency
gzip on;
gzip_min_length 860;
gzip_vary on;
gzip_proxied expired private auth;
gzip_types application/json text/plain application/javascript;
gzip_disable "MSIE [1-6]\.";
upstream django {
server $DJANGO_NGINX_UPSTREAM_URL;
}
server {
listen 8080;
server_name _;
charset utf-8;
client_max_body_size 75M;
error_page 500 /500.json;
absolute_redirect off;
location /static/ {
alias /app/static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://django;
error_page 500 /500.json;
}
location ~ ^/(v1|admin)/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://django;
error_page 500 /500.json;
}
location /500.json {
default_type application/json;
return 500 '{"detail": "An internal server error occurred."}';
}
location /terms_of_service.html {
root /var/api/api;
index terms_of_service.html;
}
location /version {
default_type "application/json";
return 200 '{"release": "$DJANGO_NGINX_GIT_REVISION", "environment": "$DJANGO_NGINX_ENVIRONMENT"}';
}
}