ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

openresty-component

2019-12-07 17:52:21  阅读:302  来源: 互联网

标签:component libdrizzle location openresty pass array ngx drizzle


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)
     '
 }
 
 

标签:component,libdrizzle,location,openresty,pass,array,ngx,drizzle
来源: https://www.cnblogs.com/justart/p/12002742.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有