Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx common parameters and redirect parameter configuration

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Translation and function of nginx parameters

The variable $arg_PARAMETER # contains the value in the GET request, if there is a variable PARAMETER.

$args # this variable is equal to the parameter in the request line (GET request), such as foo=123&bar=blahblah

$binary_remote_addr # binary customer address.

$body_bytes_sent # the number of body bytes sent in response. Even if the connection is broken, this data is accurate.

The Content-length field in the $content_length # request header.

The Content-Type field in the $content_type # request header.

The value of the $cookie_COOKIE # cookie COOKIE variable

$document_root # the value specified in the root directive is currently requested.

$document_uri # is the same as $uri.

$host # requests the host header field, otherwise it is the server name.

$hostname # Set to the machine's hostname as returned by gethostname

$http_HEADER

$is_args # if there is a $args parameter, this variable is equal to "?", otherwise equal to "", a null value.

$http_user_agent # client agent information

$http_cookie # client cookie information

The variable $limit_rate # can limit the connection rate.

$query_string # is the same as $args.

$request_body_file # temporary file name of the client requesting principal information.

$request_method # the action requested by the client, usually GET or POST.

$remote_addr # the IP address of the client.

Port of the $remote_port # client.

$remote_user # user name that has been authenticated by Auth Basic Module.

$request_completion # if the request ends, set it to OK. Null (Empty) when the request is not completed or if it is not the last in the request chain.

$request_method # GET or POST

$request_filename # the file path of the current request, generated by the root or alias directive and the URI request.

$request_uri # contains the original URI of the request parameter, without the hostname, such as "/ foo/bar.php?arg=baz". It can't be modified.

The $scheme # HTTP method (such as http,https).

The protocol used by the $server_protocol # request, usually HTTP/1.0 or HTTP/1.1.

$server_addr # server address, which can be determined after completing a system call.

$server_name # server name.

$server_port # the port number where the request arrives at the server.

$uri # the current URI,$uri without request parameters does not contain a hostname, such as "/ foo/bar.html". This value may not be consistent with $request_uri. $request_uri is the value sent by the browser. This value is the value after rewrite. For example, after doing internal redirects.

Today, when I was writing rewrite redirection rules for a website, I encountered this problem of parameter handling about redirection. By default, Nginx automatically adds the parameters from the old address after rewrite, which may be redundant for the new address redirected to. Although this will not have much impact on the result of the redirection, you will always feel uncomfortable when you notice that the new address contains an extra "? xxx=xxx". So how to deal with this part of the content? You will understand by looking at the following two simple examples.

For example:

Redirect http://example.com/test.php?para=xxx to http://example.com/new

If you write it according to the default: rewrite ^ / test.php (. *) / new permanent

The result after redirection is: http://example.com/new?para=xxx

If it is rewritten as: rewrite ^ / test.php (. *) / new? Permanent

The result is: http://example.com/new

So, the key point is "?" This suffix. What if you want to retain a particular parameter? This can be done using the $arg_PARAMETER parameter that comes with Nginx itself.

For example:

Rewrite http://example.com/test.php?para=xxx&p=xx to http://example.com/new?p=xx

It can be written as: rewrite ^ / test.php / new?p=$arg_p? Permanent

Friends who only want results can directly ignore the previous content, see here:

Rewrite ^ / test.php / new permanent; / / rewrite to the address with parameters

Rewrite ^ / test.php / new? Permanent; / / No parameters after redirection

Rewrite ^ / test.php / new?id=$arg_id? Permanent; / / redirect with the specified parameters

Permanent is a permanent redirect parameter, which can be removed as needed, but preferably with. The difference between reference 301 redirection and 302 redirection

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report