http-postgres #

ngx_postgres is an upstream module that allows nginx to communicate directly with PostgreSQL database.

Source: upstream source

Directives

postgres_connect_timeout #

syntax: postgres_connect_timeout 1 arg (duration in ms);  ·  context: http, server, location

Duration in milliseconds; accepts ms / s / m suffixes.

postgres_escape #

syntax: postgres_escape 1 arg;  ·  context: http, server, location

This directive can be used more than once within same context. postgres_escape --------------- syntax: postgres_escape $escaped [[=]$unescaped] default: none * context: http, server, location Escape and quote $unescaped string.

postgres_keepalive #

syntax: postgres_keepalive 1+ args;  ·  context: upstream

Configures the maximum pooled PostgreSQL connections, backend matching mode, and pool-overflow behavior.

postgres_output #

syntax: postgres_output 1 arg;  ·  context: http, server, location, location-if

Selects the response output format, such as rds, text, value, binary_value, or none.

postgres_pass #

syntax: postgres_pass 1 arg;  ·  context: location, location-if

Sample configuration #6 ----------------------- Use GET parameter in SQL query. location /quotes { set_unescape_uri $txt $arg_txt; postgres_escape $txt; postgres_pass database; postgres_query "SELECT * FROM quotes WHERE quote=$txt"; } Required modules (other than ngx_postgres): - ngx_set_misc.

postgres_query #

syntax: postgres_query 1+ args;  ·  context: http, server, location, location-if

Sample configuration #6 ----------------------- Use GET parameter in SQL query. location /quotes { set_unescape_uri $txt $arg_txt; postgres_escape $txt; postgres_pass database; postgres_query "SELECT * FROM quotes WHERE quote=$txt"; } Required modules (other than ngx_postgres): - ngx_set_misc.

postgres_result_timeout #

syntax: postgres_result_timeout 1 arg (duration in ms);  ·  context: http, server, location

Duration in milliseconds; accepts ms / s / m suffixes.

postgres_rewrite #

syntax: postgres_rewrite 2+ args;  ·  context: http, server, location, location-if

Rewrites the response status code when a matching row-affected or row-returned condition occurs.

postgres_server #

syntax: postgres_server 1+ args;  ·  context: upstream

Configuration directives ======================== postgres_server --------------- syntax: postgres_server {ip[:portnum]|unix:/socket/dir} [port=portnum] [dbname=dbname] [user=user] [password=pass] default: none * context: upstream Set details about the database server.

postgres_set #

syntax: postgres_set 3 args;  ·  context: http, server, location

Stores a single result-set value into a variable, optionally requiring it to be present.

Example

    location = /auth {
        internal;
        postgres_escape     $user $remote_user;
        postgres_escape     $pass $remote_passwd;
        postgres_pass       database;
        postgres_query      "select login from users where login=$user and pass=$pass";
        postgres_rewrite    no_rows 403;
        postgres_set        $login 0 0 required;
        postgres_output     none;
    }

    location /test {
        auth_request        /auth;
        auth_request_set    $auth_user $login;
        echo -n             "hi, $auth_user!";
    }

↑ back to index