schedule_redirect
The `schedule_redirect` directive enables conditional redirection of requests to a specified server within the current request context.
Description
The schedule_redirect directive is utilized within the server context of the NGINX configuration to facilitate redirects to a designated server during the processing of an incoming request. When set, this directive effectively flags the server for redirection, enabling dynamic handling of requests based on specified conditions. This is particularly useful for routing requests based on the client's characteristics or request attributes without initiating a new HTTP response cycle.
This directive can be combined with conditional checks that assess request parameters such as headers or query strings. For example, if a specific header is present, and its value meets certain criteria, this directive can automatically redirect the request to a different server while using the original request context. By maintaining the request context, the original headers and variables can still be accessed in the targeted server, allowing for a seamless transition without losing important client information.
In practice, schedule_redirect operates alongside other NGINX features, such as virtual servers and complex conditions, to provide fine-grained control over request routing. It is especially advantageous in load balancing or multi-tenant applications where requests may need to be dynamically rerouted based on various conditions.
Config Example
server {
listen 80;
server_name example.com;
# Enable scheduled redirection to the new server
schedule_redirect on;
server_redirect newserver.com;
location / {
# Normal processing code
}
}Ensure that redirects do not create circular redirection loops which can lead to server errors.
When using conditional checks with schedule_redirect, incorrect syntax can lead to unexpected behavior, so always validate the conditions set for redirecting.