-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
nginx.conf
145 lines (110 loc) · 3.15 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
env PATH;
worker_processes ${{NUM_WORKERS}};
error_log ${{NOTICE_LOG}} notice;
daemon ${{DAEMON}};
events {
worker_connections 1024;
}
http {
include mime.types;
lua_shared_dict community_view_counters 5m;
proxy_cache_path ${{IMAGE_CACHE_PATH}} levels=1:2 keys_zone=image_cache:100m max_size=15g inactive=100d use_temp_path=off;
log_format image_log '[$time_local] $request_time $request_uri - $image_log';
init_worker_by_lua_file "jobs/flush_counters.lua";
resolver ${{RESOLVER}};
resolver_timeout 4;
map $http_user_agent $is_crawler {
default 0;
"~*crawl|Googlebot|Slurp|bingbot|Ahrefs|Yandex|ia_archiver|Applebot|ysearch|Baiduspider|Exabot|SemrushBot|SMTBot|facebookexternalhit|MegaIndex|PetalBot" 1;
}
init_by_lua_block {
require "lpeg"
require "socket"
require "ltn12"
require "mime"
}
server {
listen ${{PORT}};
lua_code_cache ${{CODE_CACHE}};
include nginx/http_proxy.conf;
location / {
set $_url "";
if ($request_method = OPTIONS) {
add_header Content-Length 0;
add_header Content-Type text/plain;
access_log off;
return 200;
}
default_type text/html;
rewrite_by_lua '
require("helpers.referrers").set_register_referrer_nginx()
';
content_by_lua '
require("lapis").serve("app")
';
}
location ~ ^/img/.*\.([a-z_]*)$ {
proxy_pass http://127.0.0.1:${{PORT}};
proxy_set_header Host streak-images.local;
proxy_cache image_cache;
proxy_cache_valid 200 365d;
proxy_cache_valid 404 1m;
proxy_cache_key "$scheme$proxy_host$uri";
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;
}
location ~ ^/uploads/receive/(?<upload_id>\d+)$ {
client_max_body_size 20m;
content_by_lua_file 'handle_upload.lua';
}
location /static/ {
alias static/;
access_log off;
gzip on;
gzip_types application/x-javascript text/css image/svg+xml;
expires 3d;
gzip_comp_level 5;
}
location /favicon.ico {
alias static/favicon.ico;
access_log off;
}
location /download/ {
rewrite_by_lua_file "handle_download.lua";
alias user_content/uploads/;
}
location = /robots.txt {
access_log off;
alias static/robots.txt;
}
}
# www redirect server
server {
listen ${{PORT}};
server_name www.streak.club;
location / {
if ($http_host ~ ^www\.(?<domain>.*)$) {
rewrite ^ http://$domain$request_uri permanent;
}
}
}
server {
listen ${{PORT}};
server_name streak-images.local;
lua_code_cache ${{CODE_CACHE}};
include nginx/http_proxy.conf;
allow 127.0.0.1;
deny all;
location ~ ^/img/.*\.([a-z_]*)$ {
set $_url "";
set $image_log "";
default_type text/html;
content_by_lua 'require("lapis").serve("applications.images")';
access_log logs/image_log.log image_log;
}
}
}
# vim: set expandtab ts=2 sw=2 ft=nginx: