Code Monkey home page Code Monkey logo

nginx-sorted-querystring-module's Introduction

Nginx Sorted Querystring Module

A module to order the querystring parameters in a variable to be used as cache key.

Requests like /index.html?b=2&a=1&c=3, /index.html?b=2&c=3&a=1, /index.html?c=3&a=1&b=2, /index.html?c=3&b=2&a=1 will produce the same value for $sorted_querystring_args 'a=1&b=2&c=3'.

It is also possible remove some undesired parameter defining its name with sorted_querysting_filter_parameter, like sorted_querysting_filter_parameter b _ foo; resulting in a $sorted_querystring_args as 'a=1&c=3'

This module is not distributed with the Nginx source. See the installation instructions.

Configuration

An example:

pid logs/nginx.pid; error_log logs/nginx-main_error.log debug;

worker_processes 2;

events { worker_connections 1024; #use kqueue; # MacOS use epoll; # Linux }

http { default_type text/plain;

types {
    text/html   html;
}

log_format main  '[$time_local] $host "$request" $request_time s '
                 '$status $body_bytes_sent "$http_referer" "$http_user_agent" '
                 'cache_status: "$upstream_cache_status" args: "$args '
                 'sorted_args: "$sorted_querystring_args" ';

access_log       logs/nginx-http_access.log;

proxy_cache_path /tmp/cache levels=1:2 keys_zone=zone:10m inactive=10d max_size=100m;

server {
  listen          8080;
  server_name     localhost;

  access_log       logs/nginx-http_access.log main;

  location /filtered {
    sorted_querysting_filter_parameter v _ time b;

    proxy_set_header Host "static_files_server";
    proxy_pass http://localhost:8081;

    proxy_cache zone;
    proxy_cache_key "$sorted_querystring_args";
    proxy_cache_valid 200 1m;
  }

  location / {
    proxy_pass http://localhost:8081;

    proxy_cache zone;
    proxy_cache_key "$sorted_querystring_args";
    proxy_cache_valid 200 10m;
  }
}

server {
  listen          8081;

  location / {
    return 200 "$args\n";
  }
}

}

Variables

  • $sorted_querystring_args - just list the IP considered as remote IP on the connection

Directives

  • sorted_querystring_filter_parameter - list parameters to be filtered while using the $sorted_querystring_args variable.

Installation instructions

Download Nginx Stable source and uncompress it (ex.: to ../nginx). You must then run ./configure with --add-module pointing to this project as usual. Something in the lines of:

$ ./configure \
    --add-module=../nginx-sorted-querystring-module \
    --prefix=/home/user/dev-workspace/nginx
$ make
$ make install

Running tests

This project uses nginx_test_helper on the test suite. So, after you've installed the module, you can just download the necessary gems:

$ cd test
$ bundle install

And run rspec pointing to where your Nginx binary is (default: /usr/local/nginx/sbin/nginx):

$ NGINX_EXEC=../path/to/my/nginx rspec .

Changelog

This is still a work in progress. Be the change. And take a look on the Changelog file.

nginx-sorted-querystring-module's People

Contributors

wandenberg avatar hnakamur avatar

Watchers

william avatar James Cloos avatar

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.