forked from pieterlange/nginx-error-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
81 lines (63 loc) · 2.38 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
worker_processes 8;
worker_rlimit_nofile 262144;
events {
worker_connections 16384;
multi_accept on;
use epoll;
}
http {
# Caches information about open FDs, freqently accessed files.
open_file_cache max=100 inactive=30m;
open_file_cache_valid 20m;
open_file_cache_min_uses 2;
open_file_cache_errors off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
#Specify a charset
charset utf-8;
# Timeouts globales.
client_body_timeout 10s;
client_header_timeout 10s;
client_max_body_size 1M;
keepalive_requests 1;
keepalive_timeout 0;
include /etc/nginx/mime.types;
default_type 'text/html';
log_format upstreaminfo '$remote_addr - [$time_local] "$request" "$http_x_code.$http_x_format" $status "$http_referer" "$http_user_agent" $request_length $request_time';
access_log /var/log/nginx/access.log upstreaminfo;
error_log /var/log/nginx/error.log;
error_page 404 /404.html;
server {
listen 80 default_server reuseport;
root /var/www/html;
index 404.html;
location / {
content_by_lua_block {
local code = ngx.req.get_headers()["X-Code"] or "404"
local format = "html"
if ngx.req.get_headers()["X-Format"] == "application/json" then
format = "json"
end
local error_file = "/"..code.."."..format
res = ngx.location.capture(error_file)
if res.status ~= 200 then
altCode = string.sub(code, 1, 1)
res = ngx.location.capture("/"..altCode.."xx".."."..format)
if res.status ~= 200 then
ngx.exit(500)
end
end
ngx.status = tonumber(code)
ngx.say(res.body)
}
}
location ~ "([0-9]{3}|[0-9][a-z]{2})\.[a-z]{1,4}$" {
try_files $uri =404;
}
location /healthz {
return 200 'ok';
}
}
}