Skip to content

Instantly share code, notes, and snippets.

@allex
Last active February 11, 2020 10:17
Show Gist options
  • Save allex/b9f5206b58570d7686c6f22b8fed3144 to your computer and use it in GitHub Desktop.
Save allex/b9f5206b58570d7686c6f22b8fed3144 to your computer and use it in GitHub Desktop.
-- print all nginx variables
-- author: allex_wang
-- GistID: b9f5206b58570d7686c6f22b8fed3144
local inspect = require('inspect')
local keys = {
"args",
"binary_remote_addr",
"body_bytes_sent",
"bytes_sent",
"connection",
"connection_requests",
"content_length",
"content_type",
"document_root",
"document_uri",
"domain",
"host",
"hostname",
"http_cookie",
"http_host",
"http_origin",
"http_purge_cache",
"http_referer",
"http_user_agent",
"http_via",
"http_x_allex",
"http_x_forwarded_for",
"https",
"is_args",
"limit_rate",
"msec",
"nginx_version",
"pid",
"pipe",
"proxy_protocol_addr",
"query_string",
"realpath_root",
"remote_addr",
"remote_port",
"remote_user",
"request",
"request_body",
"request_body_file",
"request_completion",
"request_filename",
"request_length",
"request_method",
"request_time",
"request_uri",
"scheme",
"sent_http_cache_control",
"sent_http_connection",
"sent_http_content_length",
"sent_http_content_type",
"sent_http_keep_alive",
"sent_http_last_modified",
"sent_http_location",
"sent_http_transfer_encoding",
"server_addr",
"server_name",
"server_port",
"server_protocol",
"status",
"time_iso8601",
"time_local",
"uri",
"x_scheme"
}
for k,v in ipairs(keys) do
ngx.say(v, " -> ", inspect(ngx.var[v]))
end
@allex
Copy link
Author

allex commented Feb 11, 2020

  # wget -O /etc/nginx/lua/inspect.lua https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua
  # handle /echo-raw/*
  location /echo-raw {
    default_type text/plain;
    access_by_lua_file /etc/nginx/lua/nginx_vars.lua;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment