`errors` allows you to set custom error pages and enable error logging.
`errors` allows you to set custom error pages and enable error logging.
By default, error responses (HTTP status >= 400) are not logged and the client receives a plaintext error message.
By default, error responses (HTTP status >= 400) are not logged and the client receives a plaintext error message.
Using an error log, the text of each error will be recorded so you can determine what is going wrong without exposing those details to the clients. With error pages, you can present custom error messages and instruct your visitor what to do.
Using an error log, the text of each error will be recorded so you can determine what is going wrong without exposing those details to the clients. With error pages, you can present custom error messages and instruct your visitor with what to do.
## Syntax
## Syntax
...
@@ -11,7 +11,7 @@ Using an error log, the text of each error will be recorded so you can determine
...
@@ -11,7 +11,7 @@ Using an error log, the text of each error will be recorded so you can determine
errors [logfile]
errors [logfile]
~~~
~~~
*`logfile` is the path to the error log file to create (or append to), relative to the current working directory. It can also be stdout or stderr to write to the console, syslog to write to the system log (except on Windows), or visible to write the error (including full stack trace, if applicable) to the response. Writing errors to the response is NOT advised except in local debug situations. Default is stderr.
*`logfile` is the path to the error log file to create (or append to), relative to the current working directory. It can also be stdout or stderr to write to the console, syslog to write to the system log (except on Windows), or visible to write the error (including full stack trace, if applicable) to the response. Writing errors to the response is NOT advised except in local debug situations. The default is stderr.
The above syntax will simply enable error reporting on the server. To specify custom error pages, open a block:
The above syntax will simply enable error reporting on the server. To specify custom error pages, open a block:
~~~
~~~
...
@@ -20,7 +20,7 @@ errors {
...
@@ -20,7 +20,7 @@ errors {
}
}
~~~
~~~
*`what` can only `log`.
*`what` can only be `log`.
*`where` is the path to the log file (as described above) and you can enable rotation to manage the log files.
*`where` is the path to the log file (as described above) and you can enable rotation to manage the log files.
`loadbalance` acts as a round-robin DNS loadbalancer by randomizing A and AAAA records in the
`loadbalance` acts as a round-robin DNS loadbalancer by randomizing the order of A and AAAA records in the answer. See [Wikipedia](https://en.wikipedia.org/wiki/Round-robin_DNS) about the pros and cons
message. See [Wikipedia](https://en.wikipedia.org/wiki/Round-robin_DNS) about the pros and cons
on this setup.
on this setup.
It will take care to sort any CNAMEs before any address records, because some stub resolver
It will take care to sort any CNAMEs before any address records, because some stub resolver
implementation (like glibc) can't handle that.
implementations (like glibc) are particular about that.
`proxy` facilitates both a basic reverse proxy and a robust load balancer. The proxy has support for
`proxy` facilitates both a basic reverse proxy and a robust load balancer. The proxy has support for
multiple backends and adding custom headers. The load balancing features include multiple policies,
multiple backends and adding custom headers. The load balancing features include multiple policies,
health checks, and failovers. If all hosts fails their health check the proxy middleware will fail
health checks, and failovers. If all hosts fail their health check the proxy middleware will fail
back to randomly selecting a target and sending packets to it.
back to randomly selecting a target and sending packets to it.
## Syntax
## Syntax
...
@@ -35,15 +35,15 @@ proxy from to... {
...
@@ -35,15 +35,15 @@ proxy from to... {
*`fail_timeout` specifies how long to consider a backend as down after it has failed. While it is down, requests will not be routed to that backend. A backend is "down" if CoreDNS fails to communicate with it. The default value is 10 seconds ("10s").
*`fail_timeout` specifies how long to consider a backend as down after it has failed. While it is down, requests will not be routed to that backend. A backend is "down" if CoreDNS fails to communicate with it. The default value is 10 seconds ("10s").
*`max_fails` is the number of failures within fail_timeout that are needed before considering a backend to be down. If 0, the backend will never be marked as down. Default is 1.
*`max_fails` is the number of failures within fail_timeout that are needed before considering a backend to be down. If 0, the backend will never be marked as down. Default is 1.
*`health_check` will check path (on port) on each backend. If a backend returns a status code of 200-399, then that backend is healthy. If it doesn't, the backend is marked as unhealthy for duration and no requests are routed to it. If this option is not provided then health checks are disabled. The default duration is 10 seconds ("10s").
*`health_check` will check path (on port) on each backend. If a backend returns a status code of 200-399, then that backend is healthy. If it doesn't, the backend is marked as unhealthy for duration and no requests are routed to it. If this option is not provided then health checks are disabled. The default duration is 10 seconds ("10s").
*`ignored_names...` is a space-separated list of paths to exclude from proxying. Requests that match any of these paths will be passed thru.
*`ignored_names...` is a space-separated list of paths to exclude from proxying. Requests that match any of these paths will be passed through.
*`spray` when all backends are unhealth randomly pick one to send the traffic to (this is a failsafe).
*`spray` when all backends are unhealthy, randomly pick one to send the traffic to. (This is a failsafe.)
## Policies
## Policies
There are three loadbalancing policies available:
There are three load-balancing policies available:
**random* (default) - Randomly select a backend
**random* (default) - Randomly select a backend
**least_conn* - Select backend with the fewest active connections
**least_conn* - Select the backend with the fewest active connections
**round_robin* - Select backend in round-robin fashion
**round_robin* - Select the backend in round-robin fashion
All polices implement randomly spraying packets to backend hosts when *no healthy* hosts are
All polices implement randomly spraying packets to backend hosts when *no healthy* hosts are
available. This is to preeempt the case where the healthchecking (as a mechanism) fails.
available. This is to preeempt the case where the healthchecking (as a mechanism) fails.