June 06, 2015 03:25AM
Hello everyone,

Recently for some of our needs on Nginx, I am working to develop a new module on Nginx. So I have started to develop a test and basic module. My intention is to call a function before selecting one servers in upstream section. For this, I set NGX_STREAM_MODULE type. when running the nginx with new option "stream_test" in upstream configuration, I get below error :
ERROR: nginx: [emerg] "stream_test" directive is not allowed here in xxxxxx

I will appreciate if somebody assist me on this.Thanks

Following is the source code of test module
#######################################Test Module###############################
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_stream.h>
#include <ngx_stream_upstream.h>


static char *ngx_http_test(ngx_conf_t *cf, ngx_command_t *cmd,void *conf);

static ngx_command_t ngx_stream_upstream_test_commands[] =
{
{ ngx_string("stream_test"),
NGX_STREAM_SRV_CONF|NGX_CONF_NOARGS,
ngx_http_test,
0,
0,
NULL
},

ngx_null_command
};

static ngx_stream_module_t ngx_http_test_ctx =
{
NULL,NULL,NULL,NULL
};

ngx_module_t ngx_http_test_module =
{
NGX_MODULE_V1,
&ngx_http_test_ctx, /* module context */
ngx_stream_upstream_test_commands, /* module directives */
NGX_STREAM_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING

};

static char *ngx_http_test(ngx_conf_t *cf, ngx_command_t *cmd,void *conf)
{
//ngx_stream_upstream_srv_conf_t *uscf;
//uscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_upstream_module);
ngx_conf_log_error(NGX_LOG_ERR,cf,0,"Test Function was called!");
/*if (uscf->peer.init_upstream)
{
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,"Nima Test Func: load balancing method redefined");
}*/

return NGX_CONF_OK;

}
Subject Author Posted

Writing first test Nginx module

nima0102 June 06, 2015 03:25AM

Re: Writing first test Nginx module

nima0102 June 06, 2015 08:27AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready