This topic describes the built-in variables available in EdgeScript and their corresponding NGINX variables.
The following table describes the EdgeScript built-in variables.
| Built-in variable | Description | NGINX variable |
| $arg_{name} | The value of the name parameter in the query string. A query string contains the request parameters of an HTTP request. | $arg_ Note If {name} contains a hyphen (-), use the req_uri_arg function to retrieve the value instead of the $arg_ variable. For example, for the request http://example.com/1.jpg?example-demo=123, use the function req_uri_arg('example-demo') to get the value. |
| $http_{name} | The value of the specified request header. | $http_ Note If {name} contains a hyphen (-), you must replace it with an underscore (_). For example, to access the X-USER-ID header, use the variable $http_x_user_id. |
| $cookie_{name} | The value of the {name} cookie from the request cookie header. | $cookie_ Note If {name} contains a hyphen (-), use the req_cookie function to retrieve the value instead of the $cookie_ variable. For example, to get the value from a request with the cookie:example-demo=123 header, use the function req_cookie('example-demo'). |
| $scheme | The protocol type, such as http or https. | $scheme |
| $server_protocol | The protocol version, such as HTTP/1.1. | $server_protocol |
| $host | The original host from the request header. | $host |
| $uri | The original URI of the request, which excludes the query string. | None |
| $args | $args represents all request parameters as a single string, excluding the question mark (?). For example, for the request http://example.aliyundoc.com/1k.file?k1=v1&k2=v2:
| $args |
| $request_method | The request method, such as GET or POST. | $request_method |
| $request_uri | The full original request URI, including the path and query string. This is equivalent to uri + '?' + args. | $request_uri |
| $remote_addr | The client IP address (the first IP address in the x-forwarded-for request header). | $remote_addr |
Note
- The dollar sign (
$) prefix on built-in variables provides clarity and can be omitted. - Built-in variables are read-only and cannot be assigned new values.
- Each EdgeScript rule supports a maximum of 200 global variables. There is no limit on local variables. If you need to exceed the global variable limit, define a custom function and use local variables within it.
该文章对您有帮助吗?