-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnginx.conf
145 lines (113 loc) · 3.65 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
worker_processes ${{NUM_WORKERS}};
error_log stderr notice;
daemon ${{DAEMON}};
env LAPIS_ENVIRONMENT;
user leafo users;
error_log ${{NOTICE_LOG}} notice;
events {
worker_connections ${{NUM_CONNECTIONS}};
}
http {
include mime.types;
lua_shared_dict page_cache 15m;
proxy_cache_path ../ludumdare-pagecache levels=1:2 keys_zone=pagecache:100m max_size=1g inactive=2h use_temp_path=off;
proxy_cache_path ../ludumdare-imagecache levels=1:2 keys_zone=imagecache:100m max_size=5g inactive=100d use_temp_path=off;
server {
listen ${{PORT}};
lua_code_cache ${{CODE_CACHE}};
sendfile on;
include nginx/http_proxy.conf;
location / {
ssi on;
set_by_lua $cache_buster 'return require("cache_buster")';
root static;
try_files /index.html @lua;
}
location /game/ { echo_exec @lua; }
location /games/ { echo_exec @cached_lua; }
location /users/ { echo_exec @cached_lua; }
location = /events { echo_exec @lua; }
location = /search/games { echo_exec @lua; }
location /events/ { echo_exec @lua; }
location /stats { echo_exec @cached_lua; }
location /admin/ {
auth_basic "Restricted";
auth_basic_user_file secret/htpasswd;
echo_exec @lua;
}
# resized image
location ~ /game/[\w-]+/image/[\w-]+/[\w-]+ {
echo_exec @cached_image;
}
location @cached_lua {
set_by_lua $cache_key 'return require("helpers.cache_key")()';
proxy_cache pagecache;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
proxy_cache_valid 200 10m;
proxy_cache_key "${{_NAME}}:$scheme$proxy_host$uri:$cache_key";
proxy_no_cache "${{bypass_page_cache}}";
proxy_cache_bypass "${{bypass_page_cache}}";
proxy_pass http://127.0.0.1:${{PORT}};
proxy_set_header Host ludumdare.local;
proxy_set_header X-Original-Host $http_host;
proxy_set_header X-Original-Scheme $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
gzip on;
gzip_proxied any;
}
location @cached_image {
proxy_pass http://127.0.0.1:${{PORT}};
proxy_set_header Host ludumdare.local;
proxy_no_cache "${{bypass_image_cache}}";
proxy_cache_bypass "${{bypass_image_cache}}";
proxy_cache imagecache;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
expires max;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 200 365d;
proxy_cache_valid 404 1m;
proxy_cache_key "${{_NAME}}:$uri";
}
location @lua {
default_type text/html;
set $_url "";
content_by_lua "require('lapis').serve('app')";
}
location /static/ {
if ($request_filename ~* \.eot$|\.ttf$|\.woff$) {
add_header Access-Control-Allow-Origin *;
}
if ($request_filename ~* \.coffee$|\.scss$) {
return 403;
}
gzip on;
gzip_types application/x-javascript text/css;
alias static/;
}
location = /favicon.ico {
alias static/favicon.ico;
}
location = /robots.txt {
alias static/robots.txt;
}
}
server {
server_name ludumdare.local;
listen ${{PORT}};
lua_code_cache ${{CODE_CACHE}};
access_log off; # outer server will log for us
allow 127.0.0.1;
deny all;
include nginx/http_proxy.conf;
location / {
default_type text/html;
set $_url "";
content_by_lua "require('lapis').serve('app')";
}
}
}
# vim: set expandtab ts=2 sw=2 ft=nginx: