Giter Club home page Giter Club logo

nginx-ubus-module's Introduction

Donate License

Module ngx_http_read_request_body_module

The ngx_http_ubus_module module allows access ubus function directly from nginx without using cgi or additional application to connect to it Ubus is used in openwrt to gain and set data to the system. Alle the comunication are done in json format. This can be used to make gui that are based on only ubus request and calls.

This is based on uhttpd-mod-ubus module, some procedures are took from uhttpd module.

Configuration example

location /ubus {
        ubus_interpreter;
        ubus_socket_path /var/run/ubus.sock;
        ubus_script_timeout 600;
        ubus_cors off;
}

Directives

Syntax:  ubus_interpreter;
Default: โ€”
Context: location

Enable ubus_interpreter on the location set

Syntax:  ubus_socket_path;
Default: โ€”
Context: location

The path to the socket the module will connect to. Without this the module will report a json error with Internal Error

Syntax:  ubus_script_timeout;
Default: 60
Context: location

Ubus connection will be terminated after the timeout is exceeded

Syntax:  ubus_cors;
Default: 0
Context: location

Adds cors header security options to every response header

Syntax:  ubus_noauth;
Default: 0
Context: location

Only for test purpose. This will denied every request.

Thread support

With Nginx compiled with threads support --with-threads, module will use (and requires) Nginx Thread Pool feature. As Nginx configuration suggest, this module will require in the main configuration a Thread Pool and in the location section reference to the named Thread Pool with the name ubus_interpreter.

thread_pool ubus_interpreter threads=16;
location /ubus {
        ubus_interpreter;
        ubus_socket_path /var/run/ubus/ubus.sock;
        ubus_parallel_req 20;
	aio threads=ubus_interpreter;
}

Ubus itself doesn't like concurrent request so the performance benefits from this are minimal, but this will permits to speedup and prepare each request by removing the overhead of blocking nginx execution waiting for ubus response.

nginx-ubus-module's People

Contributors

ansuel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nginx-ubus-module's Issues

Cannot compile with --with-debug option

nginx-ubus-module/src/ngx_http_ubus_module.c: In function 'ubus_post_object':
nginx-ubus-module/src/ngx_http_ubus_module.c:521:40: error: 'request' undeclared (first use in this function)
  521 |     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, request->r->connection->log, 0,
      |                                        ^~~~~~~

Segmentation fault at line 756 of ngx_http_ubus_module.c

I'm using OpenWRT with nginx and luci_statistics on one of my devices and I am collecting data for quite a lot of other devices.

After adding another device the statistics overview page stopped working and I found messages in the syslog about signal 11 (SIGSEV) for nginx worker processes.
After compiling nginx with debug symbols and installing libc with debug symbols I was able to identify the origin with valgrind in line 756 of ngx_http_ubus_module.c, by the looks because in->buf->pos = 0.

After reading a little bit through the nginx API for ngx_http_read_client_request_body I figured out that this is related to client_body_buffer_size, which defaults on my device to 8192. If the request is bigger (in my case 11520) then it is stored in a temp file rather than in buffers.

From http://nginx.org/en/docs/dev/development_guide.html
"The body can be saved in memory buffers or file buffers, if the capacity specified by the client_body_buffer_size directive is not enough to fit the entire body in memory."

As a workaround I increased client_body_buffer_size to 128k, which solved the problem for me.
Probably it is not worth implementing the file read logic, as usually UBUS requests are pretty small. But I would suggest throwing an error message if in->buf->pos == 0, saying that client_body_buffer_size should be increased.

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.