This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 426
/
nginx.conf.erb
115 lines (99 loc) · 2.74 KB
/
nginx.conf.erb
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
daemon off;
worker_processes auto;
events {
use epoll;
accept_mutex on;
worker_connections <%= worker_connections %>;
}
http {
gzip on;
gzip_comp_level 6;
gzip_min_length 512;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
gzip_proxied any;
server_tokens off;
<% if logging['access'] %>
access_log logs/access.log;
<% else %>
access_log off;
<% end %>
<% if debug %>
error_log stderr debug;
rewrite_log on;
<% else %>
error_log stderr <%= logging['error'] %>;
<% end %>
include mime.types;
default_type application/octet-stream;
sendfile on;
#Must read the body in 5 seconds.
client_body_timeout 5;
server {
listen <%= port %> reuseport;
charset <%= encoding %>;
port_in_redirect off;
keepalive_timeout 5;
root <%= root %>;
<% if error_page %>
error_page 404 500 /<%= error_page %>;
<% end %>
<% if proxies.any? %>
resolver <%= resolver %>;
<% end %>
location / {
mruby_post_read_handler /app/bin/config/lib/ngx_mruby/headers.rb cache;
mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache;
<% if clean_urls %>
try_files $uri.html $uri $uri/ $fallback;
<% else %>
try_files $uri $uri/ $fallback;
<% end %>
}
<% if clean_urls %>
location ~ \.html$ {
try_files $uri =404;
}
<% end %>
<% if https_only %>
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$request_uri;
}
<% end %>
<% routes.each do |route, path| %>
location ~ ^<%= route %>$ {
set $route <%= route %>;
mruby_set $path /app/bin/config/lib/ngx_mruby/routes_path.rb cache;
mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache;
<% if clean_urls %>
try_files $uri.html $uri $uri/ $path $fallback;
<% else %>
try_files $uri $path $fallback;
<% end %>
}
<% end %>
# need this b/c setting $fallback to =404 will try #{root}=404 instead of returning a 404
location @404 {
return 404;
}
# fallback proxy named match
<% proxies.each do |location, hash| %>
set $<%= hash['name'] %> <%= hash['host'] %>;
location @<%= location %> {
rewrite ^<%= location %>/?(.*)$ <%= hash['path'] %>/$1 break;
# can reuse variable set above
proxy_pass $<%= hash['name'] %>;
proxy_ssl_server_name on;
<% %w(http https).each do |scheme| %>
proxy_redirect <%= hash["redirect_#{scheme}"] %> <%= location %>;
<% end %>
}
<% end %>
# fallback redirects named match
<% redirects.each do |path, hash| %>
location @<%= path %> {
return <%= hash['status'] || 301 %> <%= hash['url'] %>;
}
<% end %>
}
}