$args : This variable is equal to the parameters in the request line, same as $query_string $content_length : The Content-length field in the request header. $content_type : The Content-Type field in the request header. $document_root : The value specified in the root directive for the current request. $host : The request host header field, otherwise the server name. $http_user_agent : client agent information $http_cookie : client cookie information $limit_rate : This variable can limit the connection rate. $request_method : The action requested by the client, usually GET or POST. $remote_addr : The IP address of the client. $remote_port : The port of the client. $remote_user : The username that has been authenticated by the Auth Basic Module. $request_filename : The file path of the current request, generated by the root or alias directive and the URI request. $scheme : HTTP method (eg http, https). $server_protocol : The protocol used by the request, usually HTTP/1.0 or HTTP/1.1. $server_addr : The server address, which can be determined after a system call. $server_name : Server name. $server_port : The port number where the request arrives at the server. $request_uri : The original URI containing the request parameters, excluding the hostname, eg: "/foo/bar.php?arg=baz". $uri : The current URI without request parameters, $uri does not contain the hostname, such as "/foo/bar.html". $document_uri : Same as $uri.
Symbol explanation: ^ matches the beginning of the string / matches the delimiter of the domain name . matches any character except a newline * Repeat zero or more times (.*) matches any character .* matches any text $ matches the end of the string
example
server
{
listen 80;
server_name www.xyz.com;
index index.htm index.php;
root /export/home/www
//The following conditions cannot use mathematical operations. The function implemented is to visit www.abc.com/index.php?type=2&tid=id12345
//All jump to www.xyz.com/index.php?type=2&tid=id12345
if ($host = "www.abc.com" ){
rewrite ^/(.*)$ http://www.xyz.com/$1$2 permanent;
}
}
# If the file does not exist then return 400 if (!-f $request_filename) { return 400; } # If host is not xuexb.com, then 301 to xuexb.com if ( $host != "xuexb.com" ){ rewrite ^/(.*)$ https://xuexb.com/$1 permanent; } # If the request type is not POST then return 405 if ($request_method = POST) { return 405; } # If there is a=1 in the parameter then 301 to the specified domain name if ($args ~ a=1) { rewrite ^ http://example.com/ permanent; }
More exciting articles
https://xuexb.com/html/nginx-url-rewrite.html
http://seanlook.com/2015/05/17/nginx-location-rewrite/
http://blog.csdn.net/xingfujie/article/details/7337832