http-server-redirect #
Hands a request to another server block by host name, optionally only when a condition is true. Use it to move requests between virtual hosts inside one nginx. The schedule_redirect directive picks the server from the first part of the request path.
Source: upstream source
Directives
schedule_redirect #
syntax: schedule_redirect on | off (on/off flag); · context: server
Here is an example: This example redirects requests to newserver.com if the Server-Redirect header has value and value is not 0. ### Directive: schedule_redirect Syntax: schedule_redirect on | off Default: schedule_redirect off Context: server Redirect the current request to another server from the first request path.
server_redirect #
syntax: server_redirect 1 arg; · context: server
To enable named conditions, build ngx_expr_module and this module statically in the same nginx configuration. ## Conditional Syntax Conditional syntax is selected at compile time: - With ngx_expr_module, use named expr expressions and place server_redirect inside a server-level when block.
Example
http {
server {
listen 80;
server_name example.com;
# Enable schedule redirection.
schedule_redirect on;
# Requests will not arrive here unless the first path in the request path does not exist or the host in the first path is invalid.
return 400 "request path invalid";
}
server {
listen 80;
server_name newserver.com;
# You can get original host from this variable.
add_header x-original-host $server_redirect_original_host;
location / {
proxy_pass http://upstream.com;
}
}
}