1.Array Var Nginx Module ArrayVarNginxModule
location /foo {
array_split ',' $arg_files to=$array;
# use the set_quote_sql_str directive in the ngx_set_misc
# module to map to each element in the array $array:
array_map_op set_quote_sql_str $array;
array_map "name = $array_it" $array;
array_join ' or ' $array to=$sql_condition;
# well, we could feed it to ngx_drizzle to talk to MySQL, for example ;)
echo "select * from files where $sql_condition";
}
2.AuthRequestNginxModule
location /private/
{ auth_request /auth; ... }
location = /auth
{
proxy_pass ...
proxy_set_header X-Original-Uri $request_uri;
... }
3.CoolkitNginxModule
ngx_coolkit is collection of small and useful nginx add-ons. CONFIGURATION DIRECTIVES: ------------------------- override_method off | [methods] source (context: http, server, location) ------------------------------------------------------------------------ Override HTTP method. default: none CONFIGURATION VARIABLES: ------------------------ $remote_passwd ----------------- Decoded password from "Authorization" header (Basic HTTP Authentication). $location --------- Name of the matched location block. EXAMPLE CONFIGURATION #1: ------------------------- http { server { location / { override_method $arg_method; proxy_pass http://127.0.0.1:8100; } } } Pass request with changed HTTP method (based on "?method=XXX") to the backend. EXAMPLE CONFIGURATION #2: ------------------------- http { upstream database { postgres_server 127.0.0.1 dbname=test user=monty password=some_pass; } server { location = /auth { internal; set_quote_sql_str $user $remote_user; set_quote_sql_str $pass $remote_passwd; postgres_pass database; postgres_query "SELECT login FROM users WHERE login=$user AND pass=$pass"; postgres_rewrite no_rows 403; postgres_output none; } location / { auth_request /auth; root /files; } } } Restrict access to local files by authenticating against SQL database. Required modules (other than ngx_coolkit): - ngx_http_auth_request_module, - ngx_postgres (PostgreSQL) or ngx_drizzle (MySQL, Drizzle, SQLite), - ngx_set_misc.
4.Drizzle Nginx Module
Yichun Zhang , 26 Aug 2011 (created 21 Jun 2011)
This is an nginx upstream module that talks to MySQL and/or Drizzle database servers by libdrizzle.
This ngx_drizzle module is not enabled by default. You should specify the --with-http_drizzle_module
optiotn while configuring OpenResty.
The libdrizzle C library is no longer bundled by OpenResty. You need to download the drizzle server tarball from https://launchpad.net/drizzle.
When you get the drizzle7 release tarball, you can install libdrizzle-1.0 like this:
tar xzvf drizzle7-VERSION.tar.gz
cd drizzle7-VERSION/
./configure --without-server
make libdrizzle-1.0
make install-libdrizzle-1.0
where VERSION
is the drizzle7 release version number like 2011.06.20
.
Please ensure that you have the python
command point to a python2
interpreter. It's known that on recent Arch Linux distribution, python
is linked to python3
by default, and while running make libdrizzle-1.0
will yield the following error:
File "config/pandora-plugin", line 185
print "Dependency loop detected with %s" % plugin['name']
^
SyntaxError: invalid syntax
make: *** [.plugin.scan] Error 1
You can fix this by pointing python
temporarily to python2
.
When you install the libdrizzle-1.0 library to a custom path prefix, you can specify the libdrizzle prefix to OpenResty like this:
cd /path/to/ngx_openresty-VERSION/
./configure --with-libdrizzle=/path/to/drizzle --with-http_drizzle_module
https://github.com/openresty/drizzle-nginx-module#rds-header-part
drizzle_connect_timeout 1s;
drizzle_send_query_timeout 2s;
drizzle_recv_cols_timeout 1s;
drizzle_recv_rows_timeout 1s;
location /query {
drizzle_query 'select sleep(10)';
drizzle_pass my_backend;
rds_json on;
more_set_headers -s 504 'X-Mysql-Tid: $drizzle_thread_id';
}
location /kill {
drizzle_query "kill query $arg_tid";
drizzle_pass my_backend;
rds_json on;
}
location /main {
content_by_lua '
local res = ngx.location.capture("/query")
if res.status ~= ngx.HTTP_OK then
local tid = res.header["X-Mysql-Tid"]
if tid and tid ~= "" then
ngx.location.capture("/kill", { args = {tid = tid} })
end
return ngx.HTTP_INTERNAL_SERVER_ERROR;
end
ngx.print(res.body)
'
}