<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=NGINX_Snippets</id>
	<title>NGINX Snippets - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=NGINX_Snippets"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=NGINX_Snippets&amp;action=history"/>
	<updated>2026-05-10T15:54:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=NGINX_Snippets&amp;diff=168&amp;oldid=prev</id>
		<title>imported&gt;Jeremy-busk at 01:54, 8 March 2019</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=NGINX_Snippets&amp;diff=168&amp;oldid=prev"/>
		<updated>2019-03-08T01:54:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;# Most of these involve lua&lt;br /&gt;
&lt;br /&gt;
Add to location&lt;br /&gt;
&lt;br /&gt;
Return 200 with text&lt;br /&gt;
```&lt;br /&gt;
        add_header Content-Type text/plain;&lt;br /&gt;
        return 200 &amp;quot;hi&amp;quot;;&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
    default_type 'text/plain';&lt;br /&gt;
    content_by_lua_block {&lt;br /&gt;
    ngx.req.read_body()&lt;br /&gt;
    local request_body = ngx.req.get_body_data()&lt;br /&gt;
    ngx.say(request_body)&lt;br /&gt;
    ngx.say('hello')&lt;br /&gt;
    ngx.say(ngx.var.arg_id)&lt;br /&gt;
&lt;br /&gt;
    if string.find(ngx.var.request_body, &amp;quot;eth&amp;quot;) then&lt;br /&gt;
        ngx.say('contains')&lt;br /&gt;
    end&lt;br /&gt;
    if ngx.re.match(ngx.var.request_body, &amp;quot;feth&amp;quot;) then&lt;br /&gt;
       ngx.say('contains2')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
Loging vars in lua to error log&lt;br /&gt;
```&lt;br /&gt;
ngx.log(ngx.ERR, 'mytest or var');&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
p = 666&lt;br /&gt;
d = &amp;quot;23.42&amp;quot;&lt;br /&gt;
payload='{&amp;quot;d&amp;quot;:[{&amp;quot;pres&amp;quot;:'..(p)..',&amp;quot;temp&amp;quot;:&amp;quot;'..(d)..'&amp;quot;}]}'&lt;br /&gt;
t = cjson.decode(payload)&lt;br /&gt;
print(t.d[1].temp) -- prints &amp;quot;23.42&amp;quot;&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
# Getting Headers&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
local h = ngx.req.get_headers()&lt;br /&gt;
  for k, v in pairs(h) do&lt;br /&gt;
    ngx.say(k, &amp;quot;: &amp;quot;, v)&lt;br /&gt;
  end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
local redis = require &amp;quot;nginx.redis&amp;quot;&lt;br /&gt;
local rdb = redis:new()&lt;br /&gt;
rdb:set_timeout(1000) -- 1 sec&lt;br /&gt;
local ok, err = rdb:connect(&amp;quot;127.0.0.1&amp;quot;, 6379)&lt;br /&gt;
if not ok then&lt;br /&gt;
  ngx.say(&amp;quot;failed to connect: &amp;quot;, err)&lt;br /&gt;
  return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if res ~= ngx.var.http_authorization then&lt;br /&gt;
   ngx.say(&amp;quot;Failed http authorization.&amp;quot;)&lt;br /&gt;
   return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
ngx.encode_base64(&amp;quot;myuser:pass&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if res ~= ngx.var.http_authorization then&lt;br /&gt;
   ngx.say(&amp;quot;Failed http authorization.&amp;quot;)&lt;br /&gt;
   return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
# Resources&lt;br /&gt;
&lt;br /&gt;
* https://github.com/david-martin/nginx-request-body-example&lt;br /&gt;
* https://github.com/jeremybusk/openresty/blob/dev/sandbox/nginx-lua-ptables.conf&lt;/div&gt;</summary>
		<author><name>imported&gt;Jeremy-busk</name></author>
	</entry>
</feed>