{"id":19297098,"url":"https://github.com/hanadalee/ngx_http_var_module","last_synced_at":"2026-03-11T06:31:06.550Z","repository":{"id":261919019,"uuid":"884953191","full_name":"HanadaLee/ngx_http_var_module","owner":"HanadaLee","description":"Dynamically assigns new variables through predefined functions for NGINX","archived":false,"fork":false,"pushed_at":"2025-01-19T11:06:19.000Z","size":332,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T00:44:12.509Z","etag":null,"topics":["nginx","nginx-module","nginx-variable"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HanadaLee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-07T17:22:43.000Z","updated_at":"2025-01-19T11:06:20.000Z","dependencies_parsed_at":"2024-11-09T09:18:08.455Z","dependency_job_id":"9843bda9-078b-47d0-8d6c-474222357dca","html_url":"https://github.com/HanadaLee/ngx_http_var_module","commit_stats":{"total_commits":226,"total_committers":1,"mean_commits":226.0,"dds":0.0,"last_synced_commit":"c61ea70a90c798809e84f9dbb6920003151d32c8"},"previous_names":["hanadalee/ngx_http_var_module"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanadaLee%2Fngx_http_var_module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanadaLee%2Fngx_http_var_module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanadaLee%2Fngx_http_var_module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanadaLee%2Fngx_http_var_module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HanadaLee","download_url":"https://codeload.github.com/HanadaLee/ngx_http_var_module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240400291,"owners_count":19795331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx","nginx-module","nginx-variable"],"created_at":"2024-11-09T23:01:10.382Z","updated_at":"2026-03-11T06:31:06.186Z","avatar_url":"https://github.com/HanadaLee.png","language":"C","readme":"# Name\n\n`ngx_http_var_module` is a nginx module that dynamically assigns new variables through predefined functions.\n\n# Table of Content\n\n- [Name](#name)\n- [Table of Content](#table-of-content)\n- [Status](#status)\n- [Synopsis](#synopsis)\n- [Installation](#installation)\n- [Directives](#directives)\n  - [var](#var)\n- [Author](#author)\n- [License](#license)\n\n# Status\n\nThis Nginx module is currently considered experimental. Issues and PRs are welcome if you encounter any problems.\n\n# Synopsis\n\n```nginx\nserver {\n    listen 127.0.0.1:8080;\n    server_name localhost;\n\n    location / {\n        var $copy_var copy $scheme://$host$request_uri;\n    }\n}\n```\n\n# Installation\n\nTo use theses modules, configure your nginx branch with `--add-module=/path/to/ngx_http_var_module`.\n\n# Directives\n\n## var\n\n**Syntax:** *var $new_variable operator \\[-i\\] args... \\[if\\=condition\\]*\n\n**Default:** *-*\n\n**Context:** *http, server, location*\n\nDefine a variable whose value is the result of function calculation. The variable value cannot be cached and is recalculated each time it is used. If the current level does not define a variable with the same variable name using this instruction, it can be inherited from the previous level. The -i parameter is used to ignore case.\n\nThe following functions are available:\n```nginx\n#### Conditional Judgement ####\n# Returns 1 if the input parameter is empty or 0, otherwise returns 0\nvar $bool_var not str;\n\n# Returns 1 if all input parameters are non-empty and not 0, otherwise returns 0\nvar $bool_var and str1 str2...; \n\n# Returns 1 if any input parameter is non-empty and not 0, otherwise returns 0\nvar $bool_var or str1 str2...; \n\n\n#### String Judgement ####\n# Checks if the string is empty, returns 1 or 0\nvar $bool_var if_empty str;\n\n# Checks if the string is non-empty, returns 1 or 0\nvar $bool_var if_not_empty str;\n\n# Checks if the string is a number, returns 1 or 0\nvar $bool_var if_is_num str;\n\n# Checks if the strings are equal\nvar $bool_var if_str_eq [-i] str1 str2;\n\n# Checks if the strings are not equal\nvar $bool_var if_str_ne [-i] str1 str2;\n\n# Checks if the string has the specified prefix, returns 1 or 0\nvar $bool_var if_has_prefix [-i] str prefix;\n\n# Checks if the string has the specified suffix, returns 1 or 0\nvar $bool_var if_has_suffix [-i] str suffix;\n\n# Checks if the substring is present, returns 1 or 0\nvar $bool_var if_find [-i] str sub_str;\n\n\n#### General String Operations ####\n# Copy the value of the variable\nvar $new_var copy src_str;\n\n# Length of the string\nvar $new_var len src_str;\n\n# Convert to uppercase\nvar $new_var upper src_str;\n\n# Convert to lowercase\nvar $new_var lower src_str;\n\n# Trim leading and trailing whitespace characters\nvar $new_var trim src_str;\n\n# Trim leading whitespace characters\nvar $new_var ltrim src_str;\n\n# Trim trailing whitespace characters\nvar $new_var rtrim src_str;\n\n# Reverse the string\nvar $new_var reverse src_str;\n\n# Get starting position of substring\nvar $new_var find [-i] src_str sub_str;\n\n# Repeat the string a given number of times\nvar $new_var repeat src_str times;\n\n# Extract substring\nvar $new_var substr src_str start [len];\n\n# Replace keyword\nvar $new_var replace [-i] src_str src dst; \n\n\n#### Regex Judgement ####\n# Check if regex matches, returns 1 or 0\nvar $bool_var if_re_match [-i] src_str match_regex;\n\n\n#### Regex Operations ####\n# Capture regex\nvar $new_var re_capture [-i] src_str capture_regex assign_value;\n\n# Substitute regex\nvar $new_var re_sub [-i] src_str capture_regex assign_value;\n\n# Global regex substitution\nvar $new_var re_gsub [-i] src_str capture_regex assign_value;\n\n\n#### Mathematical Judgement ####\n# Check if numbers are equal, returns 1 or 0\nvar $bool_var if_eq num1 num2;\n\n# Check if numbers are not equal, returns 1 or 0\nvar $bool_var if_ne num1 num2;\n\n# Check if less than, returns 1 or 0\nvar $bool_var if_lt num1 num2;\n\n# Check if less than or equal, returns 1 or 0\nvar $bool_var if_le num1 num2;\n\n# Check if greater than, returns 1 or 0\nvar $bool_var if_gt num1 num2;\n\n# Check if greater than or equal, returns 1 or 0\nvar $bool_var if_ge num1 num2;\n\n# Check if is within the start_num-end_num range, return 1 or 0\nvar $bool_var if_range num start_num-end_num;\n\n\n### Mathematical Operations ####\n# Absolute value (returns original format without negative sign)\nvar $new_var abs num;\n\n# Maximum value (returns with original format)\nvar $new_var max num1 num2;\n\n# Minimum value (returns with original format)\nvar $new_var min num1 num2;\n\n# Integer addition\nvar $new_var add int1 int2;\n\n# Integer subtraction\nvar $new_var sub int1 int2;\n\n# Integer multiplication\nvar $new_var mul int1 int2;\n\n# Integer division, int2 cannot be 0\nvar $new_var div int1 int2;\n\n# Integer modulus, int2 cannot be 0\nvar $new_var mod int1 int2;\n\n# Round to n significant digits\nvar $new_var round src_num int;\n\n# Floor value, the largest integer less than or equal to the source\nvar $new_var floor src_num;\n\n# Ceiling value, the smallest integer greater than or equal to the source\nvar $new_var ceil src_num;\n\n# Random large positive integer\nvar $new_var rand;\n\n# Random positive integer in specified range\nvar $new_var rand_range start_int-end_int;\n\n\n#### Encoding and Decoding ####\n# Convert binary to hexadecimal\nvar $new_var hex_encode src_str;\n\n# Convert hexadecimal to binary\nvar $new_var hex_decode src_str;\n\n# Decimal to hexadecimal\nvar $new_var dec_to_hex dec;\n\n# Hexadecimal to decimal\nvar $new_var hex_to_dec hex;\n\n# Full URI encoding\nvar $new_var escape_uri src_str;\n\n# Argument encoding\nvar $new_var escape_args src_str;\n\n# URI component encoding\nvar $new_var escape_uri_component src_str;\n\n# HTML encoding\nvar $new_var escape_html src_str;\n\n# URI decoding\nvar $new_var unescape_uri src_str;\n\n# Base64 encoding\nvar $new_var base64_encode src_str;\n\n# Base64url encoding\nvar $new_var base64url_encode src_str;\n\n# Base64 decoding\nvar $new_var base64_decode src_str;\n\n# Base64url decoding\nvar $new_var base64url_decode src_str;\n\n\n#### Cryptographic Hash Calculations ####\n# CRC32 encoding (for short string)\nvar $new_var crc32_short src_str;\n\n# CRC32 encoding (for long string)\nvar $new_var crc32_long src_str;\n\n# MD5 encoding\nvar $new_var md5sum src_str;\n\n# SHA1 encoding\nvar $new_var sha1sum src_str;\n\n# SHA256 encoding\nvar $new_var sha256sum src_str;\n\n# SHA384 encoding\nvar $new_var sha384sum src_str;\n\n# SHA512 encoding\nvar $new_var sha512sum src_str;\n\n# HMAC_SHA1 encryption\nvar $new_var hmac_sha1 src_str secret;\n\n# HMAC_SHA256 encryption\nvar $new_var hmac_sha256 src_str secret;\n\n#### Time Range Judgement ####\n# Determine if the current time meets the given time range, requires at least one parameter.\n# Returns 1 if all conditions are met, otherwise returns 0.\n# The day of the week is represented by 1-7, where Sunday is 7, and timezone format is gmt+0800\nvar $bool_var time_range [year=year_range] [month=month_range] [day=day_range] [wday=wday_range(1-7)] [hour=hour_range] [min=min_range] [sec=sec_range] [timezone];\n\n\n#### Time Format ####\n# Convert timestamp to GMT time in specified format (current time if timestamp is omitted)\nvar $new_var gmt_time [src_ts] date_format;\n\n# Convert timestamp to HTTP time (current time if timestamp is omitted)\nvar $new_var gmt_time [src_ts] http_time;\n\n# Convert timestamp to cookie time (current time if timestamp is omitted)\nvar $new_var gmt_time [src_ts] cookie_time;\n\n# Convert timestamp to local time in specified format (current time if timestamp is omitted)\nvar $new_var local_time [src_ts] date_format;\n\n# Return current timestamp\nvar $new_var unixtime;\n\n# Convert HTTP time to timestamp\nvar $new_var unixtime src_http_time http_time;\n\n# Convert specified date to timestamp (return current timestamp if all are omitted)\nvar $new_var unixtime src_time date_format timezone; \n\n\n#### IP range judgment ####\n# Determine whether the IP address is within the IP range, if yes, return 1, otherwise return 0\nvar $bool_var if_ip_range ip_str ip_range_str1 ip_range_str2...;\n```\n\nAll parameters except regular expressions can contain variables. However, incorrect parameter values ​​will cause the function calculation result to be empty.\n\nVariables defined with the var directive can be overwritten by directives such as `set` and `auth_request_set`.\n\nThe if parameter enables conditional var. var will not be assign a value if the condition evaluates to “0” or an empty string. And it will continue to look for subsequent definitions of this variable.\n\n```nginx\n# When request header A is present, the value of the variable is 'have-header-a'\nvar $new_var copy have-header-a if=$http_a;\n\n# When request header A is not present but request header B is present, the value of the variable is 'have-header-b'\nvar $new_var copy have-header-b if=$http_b;\n\n# When both request header A and B are not present, the value of the variable is 'not-have-a-or-b'\nvar $new_var copy not-have-a-or-b;\n```\n\n# Author\n\nHanada im@hanada.info\n\n# License\n\nThis Nginx module is licensed under [BSD 2-Clause License](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanadalee%2Fngx_http_var_module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanadalee%2Fngx_http_var_module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanadalee%2Fngx_http_var_module/lists"}