Custom errors should be optional
This commit is contained in:
parent
e93d8d8152
commit
5faa855e66
2 changed files with 51 additions and 24 deletions
|
@ -123,18 +123,23 @@ http {
|
|||
ssl_dhparam {{ .sslDHParam }};
|
||||
{{ end }}
|
||||
|
||||
{{ $interceptHttpErrors := $cfg.interceptHttp403 || $cfg.interceptHttp404 || $cfg.interceptHttp405 ||
|
||||
$cfg.interceptHttp408 || $cfg.interceptHttp413 || $cfg.interceptHttp501 ||
|
||||
$cfg.interceptHttp502 || $cfg.interceptHttp503 || $cfg.interceptHttp504 }}
|
||||
{{ if $interceptHttpErrors }}
|
||||
# Custom error pages
|
||||
proxy_intercept_errors on;
|
||||
{{ end }}
|
||||
|
||||
error_page 403 = @custom_403;
|
||||
error_page 404 = @custom_404;
|
||||
error_page 405 = @custom_405;
|
||||
error_page 408 = @custom_408;
|
||||
error_page 413 = @custom_413;
|
||||
error_page 501 = @custom_501;
|
||||
error_page 502 = @custom_502;
|
||||
error_page 503 = @custom_503;
|
||||
error_page 504 = @custom_504;
|
||||
{{ if $cfg.interceptHttp403 }}error_page 403 = @custom_403;{{ end }}
|
||||
{{ if $cfg.interceptHttp404 }}error_page 404 = @custom_404;{{ end }}
|
||||
{{ if $cfg.interceptHttp405 }}error_page 405 = @custom_405;{{ end }}
|
||||
{{ if $cfg.interceptHttp408 }}error_page 408 = @custom_408;{{ end }}
|
||||
{{ if $cfg.interceptHttp413 }}error_page 413 = @custom_413;{{ end }}
|
||||
{{ if $cfg.interceptHttp501 }}error_page 501 = @custom_501;{{ end }}
|
||||
{{ if $cfg.interceptHttp502 }}error_page 502 = @custom_502;{{ end }}
|
||||
{{ if $cfg.interceptHttp503 }}error_page 503 = @custom_503;{{ end }}
|
||||
{{ if $cfg.interceptHttp504 }}error_page 504 = @custom_504;{{ end }}
|
||||
|
||||
# In case of errors try the next upstream server before returning an error
|
||||
proxy_next_upstream error timeout invalid_header http_502 http_503 http_504 {{ if $cfg.retryNonIdempotent }}non_idempotent{{ end }};
|
||||
|
@ -285,59 +290,67 @@ stream {
|
|||
|
||||
{{/* definition of templates to avoid repetitions */}}
|
||||
{{ define "CUSTOM_ERRORS" }}
|
||||
{{ if $cfg.interceptHttp403 }}
|
||||
location @custom_403 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(403)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp404 }}
|
||||
location @custom_404 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(404)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp405 }}
|
||||
location @custom_405 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(405)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp408 }}
|
||||
location @custom_408 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(408)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp413 }}
|
||||
location @custom_413 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(413)
|
||||
}
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp501 }}
|
||||
location @custom_501 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(501)
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp502 }}
|
||||
location @custom_502 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(502)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp503 }}
|
||||
location @custom_503 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(503)
|
||||
}
|
||||
}
|
||||
|
||||
}{{ end }}
|
||||
{{ if $cfg.interceptHttp504 }}
|
||||
location @custom_504 {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
openURL(504)
|
||||
}
|
||||
}
|
||||
}{{ end }}
|
||||
{{ end }}
|
||||
|
|
|
@ -124,6 +124,20 @@ type nginxConfiguration struct {
|
|||
// accessed using HTTPS.
|
||||
HSTSMaxAge string `structs:"hsts-max-age,omitempty"`
|
||||
|
||||
// enables or disable if HTTP codes should be passed to a client or be redirected to nginx for
|
||||
// processing with the error_page directive
|
||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
|
||||
// By default this is disabled
|
||||
InterceptHTTP403 bool `structs:"intercept-error-403,omitempty"`
|
||||
InterceptHTTP404 bool `structs:"intercept-error-404,omitempty"`
|
||||
InterceptHTTP405 bool `structs:"intercept-error-405,omitempty"`
|
||||
InterceptHTTP408 bool `structs:"intercept-error-408,omitempty"`
|
||||
InterceptHTTP413 bool `structs:"intercept-error-413,omitempty"`
|
||||
InterceptHTTP501 bool `structs:"intercept-error-502,omitempty"`
|
||||
InterceptHTTP502 bool `structs:"intercept-error-502,omitempty"`
|
||||
InterceptHTTP503 bool `structs:"intercept-error-503,omitempty"`
|
||||
InterceptHTTP504 bool `structs:"intercept-error-504,omitempty"`
|
||||
|
||||
// Time during which a keep-alive client connection will stay open on the server side.
|
||||
// The zero value disables keep-alive client connections
|
||||
// http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
|
||||
|
|
Loading…
Reference in a new issue