GithubHelp home page GithubHelp logo

nginx-keyval's Introduction

nginx-keyval

This nginx module creates variables with values taken from key-value pairs.

This module is heavily inspired by the nginx original http_keyval_module.

Dependency

Using the Redis store.

Installation

Build install

$ : "clone repository"
$ git clone https://github.com/kjdev/nginx-keyval
$ cd nginx-keyval
$ : "get nginx source"
$ NGINX_VERSION=1.x.x # specify nginx version
$ wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
$ tar -zxf nginx-${NGINX_VERSION}.tar.gz
$ cd nginx-${NGINX_VERSION}
$ : "using redis store"
$ : export NGX_KEYVAL_ZONE_REDIS=1
$ : "build module"
$ ./configure --add-dynamic-module=../
$ make && make install

Docker

$ docker build -t nginx-keyval .
$ : "app.conf: Create nginx configuration"
$ docker run -p 80:80 -v $PWD/app.conf:/etc/nginx/http.d/default.conf nginx-keyval

Github package: ghcr.io/kjdev/nginx-keyval

Configuration: ngx_http_keyval_module

Example

http {
  keyval_zone zone=one:32k;
  keyval $arg_text $text zone=one;
  ...
  server {
    ...
    location / {
      return 200 $text;
    }
  }
}

Directives

Syntax: keyval key $variable zone=name;
Default: -
Context: http

Creates a new $variable whose value is looked up by the key in the key-value database.

The database is stored in shared memory or Redis as specified by the zone parameter.

In key, you can use a mix of variables and text or just variables.

For example:

  • $remote_addr:$http_user_agent
  • '$remote_addr $http_user_agent $host "a random text"'
Syntax: keyval_zone zone=name:size [timeout=time] [ttl=time];
Default: -
Context: http

Sets the name and size of the shared memory zone that keeps the key-value database.

The optional timeout or ttl parameter sets the time to live which key-value pairs are removed (default value is 0 seconds).

Syntax: keyval_zone_redis zone=name [hostname=name] [port=number] [database=number] [connect_timeout=time] [ttl=time];
Default: -
Context: http

Using the Redis store

Sets the name of the Redis zone that keeps the key-value database.

The optional hostname parameter sets the Redis hostname (default value is 127.0.0.1).

The optional port parameter sets the Redis port (default value is 6379).

The optional database parameter sets the Redis database number (default value is 0).

The optional connect_timeout parameter sets the Redis connection timeout seconds (default value is 3).

The optional ttl parameter sets the time to live which key-value pairs are removed (default value is 0 seconds).

Configuration: ngx_stream_keyval_module

Example

stream {
  keyval_zone zone=one:32k;
  keyval $ssl_server_name $name zone=one;

  server {
    listen 12345 ssl;
    proxy_pass $name;
    ssl_certificate /usr/share/nginx/conf/cert.pem;
    ssl_certificate_key /usr/share/nginx/conf/cert.key;
  }
}

Directives

Syntax: keyval key $variable zone=name;
Default: -
Context: http

Creates a new $variable whose value is looked up by the key in the key-value database.

The database is stored in shared memory or Redis as specified by the zone parameter.

Syntax: keyval_zone zone=name:size [timeout=time] [ttl=time];
Default: -
Context: http

Sets the name and size of the shared memory zone that keeps the key-value database.

The optional timeout or ttl parameter sets the time to live which key-value pairs are removed (default value is 0 seconds).

Syntax: keyval_zone_redis zone=name [hostname=name] [port=number] [database=number] [connect_timeout=time] [ttl=time];
Default: -
Context: http

Using the Redis store

Sets the name of the Redis zone that keeps the key-value database.

The optional hostname parameter sets the Redis hostname (default value is 127.0.0.1).

The optional port parameter sets the Redis port (default value is 6379).

The optional database parameter sets the Redis database number (default value is 0).

The optional connect_timeout parameter sets the Redis connection timeout seconds (default value is 3).

The optional ttl parameter sets the time to live which key-value pairs are removed (default value is 0 seconds).

Example

TODO

  • Support for [state=file] in keyval_zone directive

nginx-keyval's People

Contributors

kjdev avatar thiagoc01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nginx-keyval's Issues

Stream

Can you make this work with the stream module?

Redis zone doesn't work

Redis zone doesn't work with Nginx 1.23.3

keyval_zone_redis zone=handler;
keyval disabled $inactive zone=handler;

redis-cli SET disabled 1

redis-cli GET disabled returns "1" but Nginx variable $inactive is empty

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.