Re: crash in ngx_add_timer

2017-04-18 Thread 胡聪 (hucc)
That`s right! I almost forgot that.




-- Original --
From:  "734819342";<734819...@qq.com>;
Send time: Wednesday, Apr 19, 2017 10:23 AM
To: "nginx-devel@nginx.org"; 

Subject:  Re: crash in ngx_add_timer




Hi,




U should not call ngx_add_timer there, cause ngx_event_timer_rbtree is 
initialized in [init process].





Ben
best regards










 Original Message 
Sender: Dk Jack
Recipient: nginx-devel@nginx.org
Date: Wednesday, Apr 19, 2017?10:03
Subject: Re: crash in ngx_add_timer


  Hi, The crash is happening at line: 
 
 ngx_add_timer(, 6);// line 81
 
 
 
 i.e. when it's trying to insert the second time. It doesn't even get to the 
handler.
 
 
 
 What would be a good value to assign to ev->log? I added:
 
 
 ev->log = cf->cycle->log
 
 
 I am still getting the crash when I try to insert the second timer.
 
 On Tue, Apr 18, 2017 at 6:53 PM, 胡聪 (hucc)   wrote:
  Hi,
 
 
 At the first glance, the ev->log should be assigned a valid value.
  
 
 
 
 -- Original --
  From:  "Dk Jack";;
 Send time: Wednesday, Apr 19, 2017 8:23 AM
 To: "nginx-devel"; 
 
 Subject:  Re: crash in ngx_add_timer
 
   
 
 resending since the attachment which had the code didn't make it... 
 
 Dk.
 
 
  #include 
 #include 
 #include 
 #include 
 #include 
 
 
 static ngx_event_t ev1;
 static ngx_event_t ev2;
 static ngx_event_t ev3;
 
 
 char ev1_data[] = "event1";
 char ev2_data[] = "event2";
 char ev3_data[] = "event3";
 
 
 static ngx_int_t
 ngx_test_handler(ngx_http_request_t *r)
 {
   if (r->main->internal) {
 return NGX_DECLINED;
   }
 
 
   r->main->internal = 1;
 
 
   ngx_table_elt_t *h;
   h = ngx_list_push(>headers_out.headers);
   h->hash = 1;
   ngx_str_set(>key, "X-NGINX-Test");
   ngx_str_set(>value, "Hello World!");
 
 
   return NGX_DECLINED;
 }
 
 
 static void
 ev1_handler(ngx_event_t* ev)
 {
   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
   ngx_add_timer(, 5);
 }
 
 
 static void
 ev2_handler(ngx_event_t* ev)
 {
   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
   ngx_add_timer(, 6);
 }
 
 
 static void
 ev3_handler(ngx_event_t* ev)
 {
   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
   ngx_add_timer(, 7);
 }
 
 
 static ngx_int_t
 ngx_test_init (ngx_conf_t *cf)
 {
   ngx_http_handler_pt *h;
   ngx_http_core_main_conf_t *cmcf;
 
 
   cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
   h = ngx_array_push(>phases[NGX_HTTP_ACCESS_PHASE].handlers);
 
 
   if (h == NULL) {
 ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access 
handler pointer");
 return NGX_ERROR;
   }
 
 
   *h = ngx_test_handler;
   ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");
 
 
   ev1.handler = ev1_handler;
   ev1.data = ev1_data;
 
 
   ev2.handler = ev2_handler;
   ev2.data = ev2_data;
 
 
   ev3.handler = ev3_handler;
   ev3.data = ev3_data;
 
 
   ngx_add_timer(, 5);
   ngx_add_timer(, 6);
   ngx_add_timer(, 7);
 
 
   return NGX_OK;
 }
 
 
 static char *
 parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
   ngx_str_t *value;
 
 
   if (cf->args->nelts != 2) {
 ngx_log_error(NGX_LOG_ERR, cf->log, 0
   , "[ss-config] invalid params for config_file. Expected 2 
received %d"
   , cf->args->nelts);
 return NGX_CONF_ERROR;
   }
 
 
   value = cf->args->elts;
 
 
   ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", [1]);
 
 
   return NGX_CONF_OK;
 }
 
 
 
 
 static ngx_http_module_t ngx_test_module_ctx = {
   NULL, /* preconfiguration */
   ngx_test_init,   /* postconfiguration */
   NULL, /* create main configuration */
   NULL, /* init main configuration */
   NULL, /* create server configuration */
   NULL, /* merge server configuration */
   NULL,/* create location configuration */
   NULL  /* merge location configuration */
 };
 
 
 static ngx_command_t ngx_test_module_cmds[] = {
   {
 ngx_string("config_file"),
 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
 parse_test_configuration,
 0,
 0,
 NULL
   }
   , ngx_null_command
 };
 
 
 ngx_module_t nginx_test_module = {
   NGX_MODULE_V1,
   _test_module_ctx,   /* module context */
   ngx_test_module_cmds,   /* module directives */
   NGX_HTTP_MODULE, /* module type */
   NULL,/* init master */
   NULL,/* init module */
   NULL,/* init process */
   NULL,

Re: crash in ngx_add_timer

2017-04-18 Thread 734819342
Hi,


  U should not call ngx_add_timer there, causengx_event_timer_rbtree is 
initialized in [init process].



Ben
best regards





Original Message
Sender:Dk jackdnj0...@gmail.com
Recipient:nginx-devel@nginx.orgnginx-de...@nginx.org
Date:Wednesday, Apr 19, 2017 10:03
Subject:Re: crash in ngx_add_timer


Hi,
The crash is happening at line:


ngx_add_timer(ev2, 6);  // line 81



i.e. when it's trying to insert the second time. It doesn't even get to the 
handler.


What would be a good value to assign to ev-log? I added:


ev-log = cf-cycle-log


I am still getting the crash when I try to insert the second timer.


On Tue, Apr 18, 2017 at 6:53 PM, 胡聪 (hucc) hucon...@foxmail.com wrote:

Hi,


At the first glance, the ev-log should be assigned a valid value.




--Original--
From: "Dk Jack";dnj0...@gmail.com;
Send time:Wednesday, Apr 19, 2017 8:23 AM
To:"nginx-devel"nginx-devel@nginx.org;
Subject: Re: crash in ngx_add_timer


resending since the attachment which had the code didn't make it...


Dk.


#include assert.h
#include nginx.h
#include ngx_config.h
#include ngx_core.h
#include ngx_http.h


static ngx_event_t ev1;
static ngx_event_t ev2;
static ngx_event_t ev3;


char ev1_data[] = "event1";
char ev2_data[] = "event2";
char ev3_data[] = "event3";


static ngx_int_t
ngx_test_handler(ngx_http_request_t *r)
{
 if (r-main-internal) {
  return NGX_DECLINED;
 }


 r-main-internal = 1;


 ngx_table_elt_t *h;
 h = ngx_list_push(r-headers_out.headers);
 h-hash = 1;
 ngx_str_set(h-key, "X-NGINX-Test");
 ngx_str_set(h-value, "Hello World!");


 return NGX_DECLINED;
}


static void
ev1_handler(ngx_event_t* ev)
{
 ngx_log_error(NGX_LOG_ERR, ev-log, 0, "received event: %s", (char *) ev-data);
 ngx_add_timer(ev1, 5);
}


static void
ev2_handler(ngx_event_t* ev)
{
 ngx_log_error(NGX_LOG_ERR, ev-log, 0, "received event: %s", (char *) ev-data);
 ngx_add_timer(ev2, 6);
}


static void
ev3_handler(ngx_event_t* ev)
{
 ngx_log_error(NGX_LOG_ERR, ev-log, 0, "received event: %s", (char *) ev-data);
 ngx_add_timer(ev3, 7);
}


static ngx_int_t
ngx_test_init (ngx_conf_t *cf)
{
 ngx_http_handler_pt *h;
 ngx_http_core_main_conf_t *cmcf;


 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 h = ngx_array_push(cmcf-phases[NGX_HTTP_ACCESS_PHASE].handlers);


 if (h == NULL) {
  ngx_log_error(NGX_LOG_ERR, cf-log, 0, "Cannot retrieve Nginx access handler 
pointer");
  return NGX_ERROR;
 }


 *h = ngx_test_handler;
 ngx_log_error(NGX_LOG_INFO, cf-log, 0, "[test] Installed test handler");


 ev1.handler = ev1_handler;
 ev1.data = ev1_data;


 ev2.handler = ev2_handler;
 ev2.data = ev2_data;


 ev3.handler = ev3_handler;
 ev3.data = ev3_data;


 ngx_add_timer(ev1, 5);
 ngx_add_timer(ev2, 6);
 ngx_add_timer(ev3, 7);


 return NGX_OK;
}


static char *
parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
 ngx_str_t *value;


 if (cf-args-nelts != 2) {
  ngx_log_error(NGX_LOG_ERR, cf-log, 0
 , "[ss-config] invalid params for config_file. Expected 2 received %d"
 , cf-args-nelts);
  return NGX_CONF_ERROR;
 }


 value = cf-args-elts;


 ngx_log_error(NGX_LOG_ERR, cf-log, 0, "file-path: %V", value[1]);


 return NGX_CONF_OK;
}




static ngx_http_module_t ngx_test_module_ctx = {
 NULL, /* preconfiguration */
 ngx_test_init,/* postconfiguration */
 NULL, /* create main configuration */
 NULL, /* init main configuration */
 NULL, /* create server configuration */
 NULL, /* merge server configuration */
 NULL,/* create location configuration */
 NULL /* merge location configuration */
};


static ngx_command_t ngx_test_module_cmds[] = {
 {
  ngx_string("config_file"),
  NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
  parse_test_configuration,
  0,
  0,
  NULL
 }
 , ngx_null_command
};


ngx_module_t nginx_test_module = {
 NGX_MODULE_V1,
 ngx_test_module_ctx,  /* module context */
 ngx_test_module_cmds,  /* module directives */
 NGX_HTTP_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
};




On Tue, Apr 18, 2017 at 5:12 PM, Dk Jack dnj0...@gmail.com wrote:

Hi,
I am new to NGinx modules and I trying to write an nginx module. I am having an 
issue
where my module crashes when adding multiple timers. The first timer adds fine.
However, when I go to add the second timer, it crashes. I've simplified the 
code to a very
basic module (which is attached to this email). The backtrace is provided as 
well.
Do I need to do some sort of initialization before I add multiple timers. Any 
advice/help
is appreciated. Thanks.


Dk.


Program received signal SIGSEGV, Segmentation fault.

Re: crash in ngx_add_timer

2017-04-18 Thread Dk Jack
Hi,
The crash is happening at line:

ngx_add_timer(, 6);// line 81

i.e. when it's trying to insert the second time. It doesn't even get to the
handler.

What would be a good value to assign to ev->log? I added:

ev->log = cf->cycle->log

I am still getting the crash when I try to insert the second timer.

On Tue, Apr 18, 2017 at 6:53 PM, 胡聪 (hucc)  wrote:

> Hi,
>
> At the first glance, the ev->log should be assigned a valid value.
>
>
> -- Original --
> *From: * "Dk Jack";;
> *Send time:* Wednesday, Apr 19, 2017 8:23 AM
> *To:* "nginx-devel";
> *Subject: * Re: crash in ngx_add_timer
>
> resending since the attachment which had the code didn't make it...
>
> Dk.
>
> #include 
> #include 
> #include 
> #include 
> #include 
>
> static ngx_event_t ev1;
> static ngx_event_t ev2;
> static ngx_event_t ev3;
>
> char ev1_data[] = "event1";
> char ev2_data[] = "event2";
> char ev3_data[] = "event3";
>
> static ngx_int_t
> ngx_test_handler(ngx_http_request_t *r)
> {
>   if (r->main->internal) {
> return NGX_DECLINED;
>   }
>
>   r->main->internal = 1;
>
>   ngx_table_elt_t *h;
>   h = ngx_list_push(>headers_out.headers);
>   h->hash = 1;
>   ngx_str_set(>key, "X-NGINX-Test");
>   ngx_str_set(>value, "Hello World!");
>
>   return NGX_DECLINED;
> }
>
> static void
> ev1_handler(ngx_event_t* ev)
> {
>   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
> ev->data);
>   ngx_add_timer(, 5);
> }
>
> static void
> ev2_handler(ngx_event_t* ev)
> {
>   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
> ev->data);
>   ngx_add_timer(, 6);
> }
>
> static void
> ev3_handler(ngx_event_t* ev)
> {
>   ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
> ev->data);
>   ngx_add_timer(, 7);
> }
>
> static ngx_int_t
> ngx_test_init (ngx_conf_t *cf)
> {
>   ngx_http_handler_pt *h;
>   ngx_http_core_main_conf_t *cmcf;
>
>   cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
>   h = ngx_array_push(>phases[NGX_HTTP_ACCESS_PHASE].handlers);
>
>   if (h == NULL) {
> ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access
> handler pointer");
> return NGX_ERROR;
>   }
>
>   *h = ngx_test_handler;
>   ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");
>
>   ev1.handler = ev1_handler;
>   ev1.data = ev1_data;
>
>   ev2.handler = ev2_handler;
>   ev2.data = ev2_data;
>
>   ev3.handler = ev3_handler;
>   ev3.data = ev3_data;
>
>   ngx_add_timer(, 5);
>   ngx_add_timer(, 6);
>   ngx_add_timer(, 7);
>
>   return NGX_OK;
> }
>
> static char *
> parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
> {
>   ngx_str_t *value;
>
>   if (cf->args->nelts != 2) {
> ngx_log_error(NGX_LOG_ERR, cf->log, 0
>   , "[ss-config] invalid params for config_file. Expected
> 2 received %d"
>   , cf->args->nelts);
> return NGX_CONF_ERROR;
>   }
>
>   value = cf->args->elts;
>
>   ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", [1]);
>
>   return NGX_CONF_OK;
> }
>
>
> static ngx_http_module_t ngx_test_module_ctx = {
>   NULL, /* preconfiguration */
>   ngx_test_init,   /* postconfiguration */
>   NULL, /* create main configuration */
>   NULL, /* init main configuration */
>   NULL, /* create server configuration */
>   NULL, /* merge server configuration */
>   NULL,   /* create location configuration */
>   NULL /* merge location configuration */
> };
>
> static ngx_command_t ngx_test_module_cmds[] = {
>   {
> ngx_string("config_file"),
> NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
> parse_test_configuration,
> 0,
> 0,
> NULL
>   }
>   , ngx_null_command
> };
>
> ngx_module_t nginx_test_module = {
>   NGX_MODULE_V1,
>   _test_module_ctx,   /* module context */
>   ngx_test_module_cmds,   /* module directives */
>   NGX_HTTP_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
> };
>
>
> On Tue, Apr 18, 2017 at 5:12 PM, Dk Jack  wrote:
>
>> Hi,
>> I am new to NGinx modules and I trying to write an nginx module. I am
>> having an issue
>> where my module crashes when adding multiple timers. The first timer adds
>> fine.
>> However, when I go to add the second timer, it crashes. I've simplified
>> the code to a very
>> basic module (which is attached to this email). The 

Re: crash in ngx_add_timer

2017-04-18 Thread 胡聪 (hucc)
Hi,


At the first glance, the ev->log should be assigned a valid value.




-- Original --
From:  "Dk Jack";;
Send time: Wednesday, Apr 19, 2017 8:23 AM
To: "nginx-devel"; 

Subject:  Re: crash in ngx_add_timer



resending since the attachment which had the code didn't make it...

Dk.


#include 
#include 
#include 
#include 
#include 


static ngx_event_t ev1;
static ngx_event_t ev2;
static ngx_event_t ev3;


char ev1_data[] = "event1";
char ev2_data[] = "event2";
char ev3_data[] = "event3";


static ngx_int_t
ngx_test_handler(ngx_http_request_t *r)
{
  if (r->main->internal) {
return NGX_DECLINED;
  }


  r->main->internal = 1;


  ngx_table_elt_t *h;
  h = ngx_list_push(>headers_out.headers);
  h->hash = 1;
  ngx_str_set(>key, "X-NGINX-Test");
  ngx_str_set(>value, "Hello World!");


  return NGX_DECLINED;
}


static void
ev1_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
  ngx_add_timer(, 5);
}


static void
ev2_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
  ngx_add_timer(, 6);
}


static void
ev3_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) 
ev->data);
  ngx_add_timer(, 7);
}


static ngx_int_t
ngx_test_init (ngx_conf_t *cf)
{
  ngx_http_handler_pt *h;
  ngx_http_core_main_conf_t *cmcf;


  cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
  h = ngx_array_push(>phases[NGX_HTTP_ACCESS_PHASE].handlers);


  if (h == NULL) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access 
handler pointer");
return NGX_ERROR;
  }


  *h = ngx_test_handler;
  ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");


  ev1.handler = ev1_handler;
  ev1.data = ev1_data;


  ev2.handler = ev2_handler;
  ev2.data = ev2_data;


  ev3.handler = ev3_handler;
  ev3.data = ev3_data;


  ngx_add_timer(, 5);
  ngx_add_timer(, 6);
  ngx_add_timer(, 7);


  return NGX_OK;
}


static char *
parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
  ngx_str_t *value;


  if (cf->args->nelts != 2) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0
  , "[ss-config] invalid params for config_file. Expected 2 
received %d"
  , cf->args->nelts);
return NGX_CONF_ERROR;
  }


  value = cf->args->elts;


  ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", [1]);


  return NGX_CONF_OK;
}




static ngx_http_module_t ngx_test_module_ctx = {
  NULL, /* preconfiguration */
  ngx_test_init,/* 
postconfiguration */
  NULL, /* create main configuration */
  NULL, /* init main configuration */
  NULL, /* create server configuration */
  NULL, /* merge server configuration */
  NULL, 
/* create location configuration */
  NULL  
/* merge location configuration */
};


static ngx_command_t ngx_test_module_cmds[] = {
  {
ngx_string("config_file"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
parse_test_configuration,
0,
0,
NULL
  }
  , ngx_null_command
};


ngx_module_t nginx_test_module = {
  NGX_MODULE_V1,
  _test_module_ctx,  /* module 
context */
  ngx_test_module_cmds,  /* module 
directives */
  NGX_HTTP_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
};



On Tue, Apr 18, 2017 at 5:12 PM, Dk Jack  wrote:
Hi,I am new to NGinx modules and I trying to write an nginx module. I am having 
an issue
where my module crashes when adding multiple timers. The first timer adds fine.
However, when I go to add the second timer, it crashes. I've simplified the 
code to a very
basic module (which is attached to this email). The backtrace is provided as 
well.
Do I need to do some sort of initialization before I add multiple timers. Any 
advice/help
is appreciated. Thanks.


Dk.


Program received signal SIGSEGV, Segmentation fault.
0x in ?? ()
(gdb) bt
#0  0x in ?? ()
#1  0x0040d68b in ngx_rbtree_insert (tree=0x69dda0 
,
node=node@entry=0x69db08 ) at 

Re: crash in ngx_add_timer

2017-04-18 Thread Dk Jack
resending since the attachment which had the code didn't make it...

Dk.

#include 
#include 
#include 
#include 
#include 

static ngx_event_t ev1;
static ngx_event_t ev2;
static ngx_event_t ev3;

char ev1_data[] = "event1";
char ev2_data[] = "event2";
char ev3_data[] = "event3";

static ngx_int_t
ngx_test_handler(ngx_http_request_t *r)
{
  if (r->main->internal) {
return NGX_DECLINED;
  }

  r->main->internal = 1;

  ngx_table_elt_t *h;
  h = ngx_list_push(>headers_out.headers);
  h->hash = 1;
  ngx_str_set(>key, "X-NGINX-Test");
  ngx_str_set(>value, "Hello World!");

  return NGX_DECLINED;
}

static void
ev1_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
ev->data);
  ngx_add_timer(, 5);
}

static void
ev2_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
ev->data);
  ngx_add_timer(, 6);
}

static void
ev3_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *)
ev->data);
  ngx_add_timer(, 7);
}

static ngx_int_t
ngx_test_init (ngx_conf_t *cf)
{
  ngx_http_handler_pt *h;
  ngx_http_core_main_conf_t *cmcf;

  cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
  h = ngx_array_push(>phases[NGX_HTTP_ACCESS_PHASE].handlers);

  if (h == NULL) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access
handler pointer");
return NGX_ERROR;
  }

  *h = ngx_test_handler;
  ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");

  ev1.handler = ev1_handler;
  ev1.data = ev1_data;

  ev2.handler = ev2_handler;
  ev2.data = ev2_data;

  ev3.handler = ev3_handler;
  ev3.data = ev3_data;

  ngx_add_timer(, 5);
  ngx_add_timer(, 6);
  ngx_add_timer(, 7);

  return NGX_OK;
}

static char *
parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
  ngx_str_t *value;

  if (cf->args->nelts != 2) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0
  , "[ss-config] invalid params for config_file. Expected 2
received %d"
  , cf->args->nelts);
return NGX_CONF_ERROR;
  }

  value = cf->args->elts;

  ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", [1]);

  return NGX_CONF_OK;
}


static ngx_http_module_t ngx_test_module_ctx = {
  NULL, /* preconfiguration */
  ngx_test_init,   /* postconfiguration */
  NULL, /* create main configuration */
  NULL, /* init main configuration */
  NULL, /* create server configuration */
  NULL, /* merge server configuration */
  NULL,   /* create location configuration */
  NULL /* merge location configuration */
};

static ngx_command_t ngx_test_module_cmds[] = {
  {
ngx_string("config_file"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
parse_test_configuration,
0,
0,
NULL
  }
  , ngx_null_command
};

ngx_module_t nginx_test_module = {
  NGX_MODULE_V1,
  _test_module_ctx,   /* module context */
  ngx_test_module_cmds,   /* module directives */
  NGX_HTTP_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
};


On Tue, Apr 18, 2017 at 5:12 PM, Dk Jack  wrote:

> Hi,
> I am new to NGinx modules and I trying to write an nginx module. I am
> having an issue
> where my module crashes when adding multiple timers. The first timer adds
> fine.
> However, when I go to add the second timer, it crashes. I've simplified
> the code to a very
> basic module (which is attached to this email). The backtrace is provided
> as well.
> Do I need to do some sort of initialization before I add multiple timers.
> Any advice/help
> is appreciated. Thanks.
>
> Dk.
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x in ?? ()
> (gdb) bt
> #0  0x in ?? ()
> #1  0x0040d68b in ngx_rbtree_insert (tree=0x69dda0
> ,
> node=node@entry=0x69db08 ) at src/core/ngx_rbtree.c:44
> #2  0x0046ceb2 in ngx_event_add_timer (timer=6, ev=0x69dae0 )
> at src/event/ngx_event_timer.h:84
> #3  ngx_test_init (cf=)
> at /home/ubuntu/git/mitigator/nginx/build/../modules/nginx_
> mitigator_module/platform/nginx-test-module.c:81
> #4  0x00424e83 in ngx_http_block (cf=0x7fffe0a0,
> cmd=,
> conf=) at src/http/ngx_http.c:315
> #5  0x0041446b in ngx_conf_handler (last=1, cf=0x7fffe0a0)
> at src/core/ngx_conf_file.c:427
> #6  ngx_conf_parse (cf=cf@entry=0x7fffe0a0, filename=filename@entry=
> 

crash in ngx_add_timer

2017-04-18 Thread Dk Jack
Hi,
I am new to NGinx modules and I trying to write an nginx module. I am
having an issue
where my module crashes when adding multiple timers. The first timer adds
fine.
However, when I go to add the second timer, it crashes. I've simplified the
code to a very
basic module (which is attached to this email). The backtrace is provided
as well.
Do I need to do some sort of initialization before I add multiple timers.
Any advice/help
is appreciated. Thanks.

Dk.

Program received signal SIGSEGV, Segmentation fault.
0x in ?? ()
(gdb) bt
#0  0x in ?? ()
#1  0x0040d68b in ngx_rbtree_insert (tree=0x69dda0
,
node=node@entry=0x69db08 ) at src/core/ngx_rbtree.c:44
#2  0x0046ceb2 in ngx_event_add_timer (timer=6, ev=0x69dae0 )
at src/event/ngx_event_timer.h:84
#3  ngx_test_init (cf=)
at
/home/ubuntu/git/mitigator/nginx/build/../modules/nginx_mitigator_module/platform/nginx-test-module.c:81
#4  0x00424e83 in ngx_http_block (cf=0x7fffe0a0, cmd=,
conf=) at src/http/ngx_http.c:315
#5  0x0041446b in ngx_conf_handler (last=1, cf=0x7fffe0a0)
at src/core/ngx_conf_file.c:427
#6  ngx_conf_parse (cf=cf@entry=0x7fffe0a0, filename=filename@entry
=0x6ad570)
at src/core/ngx_conf_file.c:283
#7  0x00411e1a in ngx_init_cycle (old_cycle=old_cycle@entry
=0x7fffe260)
at src/core/ngx_cycle.c:268
#8  0x00404208 in main (argc=, argv=)
at src/core/nginx.c:268
(gdb)
#include 
#include 
#include 
#include 
#include 

static ngx_event_t ev1;
static ngx_event_t ev2;
static ngx_event_t ev3;

char ev1_data[] = "event1";
char ev2_data[] = "event2";
char ev3_data[] = "event3";

static ngx_int_t
ngx_test_handler(ngx_http_request_t *r)
{
  if (r->main->internal) {
return NGX_DECLINED;
  }

  r->main->internal = 1;

  ngx_table_elt_t *h;
  h = ngx_list_push(>headers_out.headers);
  h->hash = 1;
  ngx_str_set(>key, "X-NGINX-Test");
  ngx_str_set(>value, "Hello World!");

  return NGX_DECLINED;
}

static void
ev1_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);
  ngx_add_timer(, 5);
}

static void
ev2_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);
  ngx_add_timer(, 6);
}

static void
ev3_handler(ngx_event_t* ev)
{
  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);
  ngx_add_timer(, 7);
}

static ngx_int_t
ngx_test_init (ngx_conf_t *cf)
{
  ngx_http_handler_pt *h;
  ngx_http_core_main_conf_t *cmcf;

  cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
  h = ngx_array_push(>phases[NGX_HTTP_ACCESS_PHASE].handlers);

  if (h == NULL) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access handler pointer");
return NGX_ERROR;
  }

  *h = ngx_test_handler;
  ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");

  ev1.handler = ev1_handler;
  ev1.data = ev1_data;

  ev2.handler = ev2_handler;
  ev2.data = ev2_data;

  ev3.handler = ev3_handler;
  ev3.data = ev3_data;

  ngx_add_timer(, 5);
  ngx_add_timer(, 6);
  ngx_add_timer(, 7);

  return NGX_OK;
}

static char *
parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
  ngx_str_t *value;

  if (cf->args->nelts != 2) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0
  , "[ss-config] invalid params for config_file. Expected 2 received %d"
  , cf->args->nelts);
return NGX_CONF_ERROR;
  }

  value = cf->args->elts;

  ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", [1]);

  return NGX_CONF_OK;
}


static ngx_http_module_t ngx_test_module_ctx = {
  NULL, /* preconfiguration */
  ngx_test_init,  	/* postconfiguration */
  NULL, /* create main configuration */
  NULL, /* init main configuration */
  NULL, /* create server configuration */
  NULL, /* merge server configuration */
  NULL,   /* create location configuration */
  NULL /* merge location configuration */
};

static ngx_command_t ngx_test_module_cmds[] = {
  {
ngx_string("config_file"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
parse_test_configuration,
0,
0,
NULL
  }
  , ngx_null_command
};

ngx_module_t nginx_test_module = {
  NGX_MODULE_V1,
  _test_module_ctx,  	 /* module context */
  ngx_test_module_cmds,  	 /* module directives */
  NGX_HTTP_MODULE, /* module type */
  NULL,/* init master */
  NULL,/* init module */
  NULL,/* init process */
  NULL,/* init thread */
  NULL,/* exit thread */
  NULL,/* exit process */
  NULL,  

Re: Nginx as a Proxy for WSUS static caching not working

2017-04-18 Thread nnvc
Dear good afternoon

I'm going through the same situation.

Did you solve it?

thank's

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,220614,273712#msg-273712

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


[nginx] Sub filter: restored ngx_http_set_ctx() at the proper place.

2017-04-18 Thread Sergey Kandaurov
details:   http://hg.nginx.org/nginx/rev/201038680680
branches:  
changeset: 6984:201038680680
user:  Sergey Kandaurov 
date:  Tue Apr 18 19:55:23 2017 +0300
description:
Sub filter: restored ngx_http_set_ctx() at the proper place.

Previously, ngx_http_sub_header_filter() could fail with a partially
initialized context, later accessed in ngx_http_sub_body_filter()
if called from the perl content handler.

The issue had appeared in 2c045e5b8291 (1.9.4).

A better fix would be to handle ngx_http_send_header() errors in
the perl module, though this doesn't seem to be easy enough.

diffstat:

 src/http/modules/ngx_http_sub_filter_module.c |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (21 lines):

diff -r 3518287d995e -r 201038680680 
src/http/modules/ngx_http_sub_filter_module.c
--- a/src/http/modules/ngx_http_sub_filter_module.c Tue Apr 18 16:08:46 
2017 +0300
+++ b/src/http/modules/ngx_http_sub_filter_module.c Tue Apr 18 19:55:23 
2017 +0300
@@ -248,8 +248,6 @@ ngx_http_sub_header_filter(ngx_http_requ
  ctx->matches->nelts);
 }
 
-ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module);
-
 ctx->saved.data = ngx_pnalloc(r->pool, ctx->tables->max_match_len - 1);
 if (ctx->saved.data == NULL) {
 return NGX_ERROR;
@@ -260,6 +258,8 @@ ngx_http_sub_header_filter(ngx_http_requ
 return NGX_ERROR;
 }
 
+ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module);
+
 ctx->offset = ctx->tables->min_match_len - 1;
 ctx->last_out = >out;
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: Welcome to nginx on Debian!

2017-04-18 Thread shiz
/var/www/html/index.nginx-debian.html

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,273701,273710#msg-273710

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


nginx-extras

2017-04-18 Thread Jeff Dyke
I realize this may not be the best place to ask, but thought someone may
know.

I am using nginx-extras which runs 1.10, for some very helpful lua
functionality, and nginx stable just hit the apt repositories on 1.12, does
anyone know how quickly nginx-extras may be updated to 1.12?

I would like to avoid self compilation as all machines are managed via
saltstack. and i would like to take advantage of the latest stable.

Thanks for any info, even if only historical knowledge.  I'll also put this
on the ubuntu lists, but feel it will just get lost in the volume.

Best,
Jeff
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

[nginx] SSL: compatibility with OpenSSL master branch.

2017-04-18 Thread Sergey Kandaurov
details:   http://hg.nginx.org/nginx/rev/3518287d995e
branches:  
changeset: 6983:3518287d995e
user:  Sergey Kandaurov 
date:  Tue Apr 18 16:08:46 2017 +0300
description:
SSL: compatibility with OpenSSL master branch.

The SSL_CTRL_SET_CURVES_LIST macro is removed in the OpenSSL master branch.
SSL_CTX_set1_curves_list is preserved as compatibility with previous versions.

diffstat:

 src/event/ngx_event_openssl.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r ac9b1df5b246 -r 3518287d995e src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c Tue Apr 18 16:08:44 2017 +0300
+++ b/src/event/ngx_event_openssl.c Tue Apr 18 16:08:46 2017 +0300
@@ -1090,7 +1090,7 @@ ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_s
  * maximum interoperability.
  */
 
-#ifdef SSL_CTRL_SET_CURVES_LIST
+#if (defined SSL_CTX_set1_curves_list || defined SSL_CTRL_SET_CURVES_LIST)
 
 /*
  * OpenSSL 1.0.2+ allows configuring a curve list instead of a single
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] SSL: added support for TLSv1.3 in ssl_protocols directive.

2017-04-18 Thread Sergey Kandaurov
details:   http://hg.nginx.org/nginx/rev/08dc60979133
branches:  
changeset: 6981:08dc60979133
user:  Sergey Kandaurov 
date:  Tue Apr 18 15:12:38 2017 +0300
description:
SSL: added support for TLSv1.3 in ssl_protocols directive.

Support for the TLSv1.3 protocol will be introduced in OpenSSL 1.1.1.

diffstat:

 src/event/ngx_event_openssl.c|  6 ++
 src/event/ngx_event_openssl.h|  1 +
 src/http/modules/ngx_http_proxy_module.c |  1 +
 src/http/modules/ngx_http_ssl_module.c   |  1 +
 src/http/modules/ngx_http_uwsgi_module.c |  1 +
 src/mail/ngx_mail_ssl_module.c   |  1 +
 src/stream/ngx_stream_proxy_module.c |  1 +
 src/stream/ngx_stream_ssl_module.c   |  1 +
 8 files changed, 13 insertions(+), 0 deletions(-)

diffs (93 lines):

diff -r dbb0c854e308 -r 08dc60979133 src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c Tue Apr 11 16:41:53 2017 +0300
+++ b/src/event/ngx_event_openssl.c Tue Apr 18 15:12:38 2017 +0300
@@ -323,6 +323,12 @@ ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_
 SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
 }
 #endif
+#ifdef SSL_OP_NO_TLSv1_3
+SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
+if (!(protocols & NGX_SSL_TLSv1_3)) {
+SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
+}
+#endif
 
 #ifdef SSL_OP_NO_COMPRESSION
 SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_COMPRESSION);
diff -r dbb0c854e308 -r 08dc60979133 src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h Tue Apr 11 16:41:53 2017 +0300
+++ b/src/event/ngx_event_openssl.h Tue Apr 18 15:12:38 2017 +0300
@@ -131,6 +131,7 @@ typedef struct {
 #define NGX_SSL_TLSv10x0008
 #define NGX_SSL_TLSv1_1  0x0010
 #define NGX_SSL_TLSv1_2  0x0020
+#define NGX_SSL_TLSv1_3  0x0040
 
 
 #define NGX_SSL_BUFFER   1
diff -r dbb0c854e308 -r 08dc60979133 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c  Tue Apr 11 16:41:53 2017 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c  Tue Apr 18 15:12:38 2017 +0300
@@ -235,6 +235,7 @@ static ngx_conf_bitmask_t  ngx_http_prox
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
diff -r dbb0c854e308 -r 08dc60979133 src/http/modules/ngx_http_ssl_module.c
--- a/src/http/modules/ngx_http_ssl_module.cTue Apr 11 16:41:53 2017 +0300
+++ b/src/http/modules/ngx_http_ssl_module.cTue Apr 18 15:12:38 2017 +0300
@@ -57,6 +57,7 @@ static ngx_conf_bitmask_t  ngx_http_ssl_
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
diff -r dbb0c854e308 -r 08dc60979133 src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c  Tue Apr 11 16:41:53 2017 +0300
+++ b/src/http/modules/ngx_http_uwsgi_module.c  Tue Apr 18 15:12:38 2017 +0300
@@ -129,6 +129,7 @@ static ngx_conf_bitmask_t  ngx_http_uwsg
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
diff -r dbb0c854e308 -r 08dc60979133 src/mail/ngx_mail_ssl_module.c
--- a/src/mail/ngx_mail_ssl_module.cTue Apr 11 16:41:53 2017 +0300
+++ b/src/mail/ngx_mail_ssl_module.cTue Apr 18 15:12:38 2017 +0300
@@ -42,6 +42,7 @@ static ngx_conf_bitmask_t  ngx_mail_ssl_
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
diff -r dbb0c854e308 -r 08dc60979133 src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c  Tue Apr 11 16:41:53 2017 +0300
+++ b/src/stream/ngx_stream_proxy_module.c  Tue Apr 18 15:12:38 2017 +0300
@@ -103,6 +103,7 @@ static ngx_conf_bitmask_t  ngx_stream_pr
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
diff -r dbb0c854e308 -r 08dc60979133 src/stream/ngx_stream_ssl_module.c
--- a/src/stream/ngx_stream_ssl_module.cTue Apr 11 16:41:53 2017 +0300
+++ b/src/stream/ngx_stream_ssl_module.cTue Apr 18 15:12:38 2017 +0300
@@ -45,6 +45,7 @@ static ngx_conf_bitmask_t  ngx_stream_ss
 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
+{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
 { ngx_null_string, 0 }
 };
 
___

[nginx] SSL: disabled renegotiation detection in client mode.

2017-04-18 Thread Sergey Kandaurov
details:   http://hg.nginx.org/nginx/rev/ac9b1df5b246
branches:  
changeset: 6982:ac9b1df5b246
user:  Sergey Kandaurov 
date:  Tue Apr 18 16:08:44 2017 +0300
description:
SSL: disabled renegotiation detection in client mode.

CVE-2009-3555 is no longer relevant and mitigated by the renegotiation
info extension (secure renegotiation).  On the other hand, unexpected
renegotiation still introduces potential security risks, and hence we do
not allow renegotiation on the server side, as we never request renegotiation.

On the client side the situation is different though.  There are backends
which explicitly request renegotiation, and disabled renegotiation
introduces interoperability problems.  This change allows renegotiation
on the client side, and fixes interoperability problems as observed with
such backends (ticket #872).

Additionally, with TLSv1.3 the SSL_CB_HANDSHAKE_START flag is currently set
by OpenSSL when receiving a NewSessionTicket message, and was detected by
nginx as a renegotiation attempt.  This looks like a bug in OpenSSL, though
this change also allows better interoperability till the problem is fixed.

diffstat:

 src/event/ngx_event_openssl.c |  4 +++-
 src/event/ngx_event_openssl.h |  5 +
 2 files changed, 8 insertions(+), 1 deletions(-)

diffs (29 lines):

diff -r 08dc60979133 -r ac9b1df5b246 src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c Tue Apr 18 15:12:38 2017 +0300
+++ b/src/event/ngx_event_openssl.c Tue Apr 18 16:08:44 2017 +0300
@@ -837,7 +837,9 @@ ngx_ssl_info_callback(const ngx_ssl_conn
 BIO   *rbio, *wbio;
 ngx_connection_t  *c;
 
-if (where & SSL_CB_HANDSHAKE_START) {
+if ((where & SSL_CB_HANDSHAKE_START)
+&& SSL_is_server((ngx_ssl_conn_t *) ssl_conn))
+{
 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
 
 if (c->ssl->handshaked) {
diff -r 08dc60979133 -r ac9b1df5b246 src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h Tue Apr 18 15:12:38 2017 +0300
+++ b/src/event/ngx_event_openssl.h Tue Apr 18 16:08:44 2017 +0300
@@ -54,6 +54,11 @@
 #define ngx_ssl_conn_t  SSL
 
 
+#if (OPENSSL_VERSION_NUMBER < 0x10002000L)
+#define SSL_is_server(s)(s)->server
+#endif
+
+
 struct ngx_ssl_s {
 SSL_CTX*ctx;
 ngx_log_t  *log;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: listen unix socket - после перезагрузки Nginx - failed (98: Address already in use)

2017-04-18 Thread Konstantin Pavlov
Здравствуйте,

On 17/04/2017 20:26, S.A.N wrote:
> Maxim Dounin Wrote:
>> Но в целом идея, что для остановки nginx'а системными скриптами 
>> надо использовать QUIT - она, скажем так, странная.
> 
> Да, странно зачем в дистрибутиве от Nginx, в файле nginx.service указан QUIT
> сигнал
> 
> ExecStop=/bin/kill -s QUIT $MAINPID
> 
> Если удалить эту строчку, Systemd при остановке и перезагрузки сервиса,
> отправляет TERM сигнал.
> Спасибо!

Спасибо, поправил в http://hg.nginx.org/pkg-oss/rev/fa1476eab346 - будет в 
следующем релизе "из коробки".

-- 
Konstantin Pavlov
___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: upstream - behavior on pool exhaustion

2017-04-18 Thread B.R. via nginx
'down' should not translate into any kind of attempt, so nothing should
really appear for the servers in that static state.
For 'unavailable' servers, for the most part the content of the variables
should be the same.

Starting from the example I provided, here is what I expected to see:
- $upstream_addr: :, :, :, :, :, :
- $upstream_response_time: 0.000, 0.000, 0.000, 0.000, 0.001, 0.000

That, associated with the 502 response from the HTTP language, is
sufficient to interpret the log entry as: the request failed to find a
proper backend after having attempted communication with the 6 specified
active backends. It is pretty straightforward.
If you want to add something to explicitely states the whole upstream group
is down, this should go to the error log.
At the very least, if the current way of working is kept, the grammar of
the content of the $upstream_* variables should be specified.

​Does not that seem reasonable?
---
*B. R.*

On Mon, Apr 17, 2017 at 6:09 PM, Ruslan Ermilov  wrote:

> On Sat, Apr 15, 2017 at 03:55:20AM +0200, B.R. via nginx wrote:
> > Let me be clear here:
> > I got 6 active servers (not marked down), and the logs show 1 attempt on
> > each. They all failed for a known reason, and there is no problem there.
> > Subsequently, the whole pool was 'down' and the response was 502.
> > Everything perfectly normal so far.
> >
> > ​What is unclear is the feature (as you classified it) of having a fake
> > node named after the pool appearing in the list of tried upstream
> servers.​
> > It brings confusion more than anything else: having a 502 response + the
> > list of all tried (and failed) nodes corresponding with the list of
> active
> > nodes is more than enough to describe what happened.
> > The name of the upstream group does not corresponding to any real asset,
> it
> > is purely virtual classification. It thus makes no sense at all to me to
> > have it appearing as a 7th 'node' in the list... and how do you interpret
> > its response time (where you got also a 7th item in the list)?
> > Moreover, it is confusing, since proxy_pass handles domain names and one
> > could believe nginx treated the upstream group name as such.
>
> Without the six attempts, if all of the servers are unreachable (either
> "down" or "unavailable" because they have failed previously) at the time
> the request starts, what do you expect to see in $upstream_*?
>
> > On Fri, Apr 14, 2017 at 10:21 AM, Ruslan Ermilov  wrote:
> >
> > > On Fri, Apr 14, 2017 at 09:41:36AM +0200, B.R. via nginx wrote:
> > > > Hello,
> > > >
> > > > Reading from upstream
> > > >  l#upstream>
> > > > docs, on upstream pool exhaustion, every backend should be tried
> once,
> > > and
> > > > then if all fail the response should be crafted based on the one
> from the
> > > > last server attempt.
> > > > So far so good.
> > > >
> > > > I recently faced a server farm which implements a dull nightly
> restart of
> > > > every node, not sequencing it, resulting in the possibility of
> having all
> > > > nodes offline at the same time.
> > > >
> > > > However, I collected log entries which did not match what I was
> expected.
> > > > For 6 backend nodes, I got:
> > > > - log format: $status $body_bytes_sent $request_time $upstream_addr
> > > > $upstream_response_time
> > > > - log entry: 502 568 0.001 :,  2>:,
> > > > :, :, :,
>  > > > address 6>:, php-fpm 0.000, 0.000, 0.000, 0.000, 0.001, 0.000,
> > > 0.000
> > > > I got 7 entries for $upstream_addr & $upstream_response_time,
> instead of
> > > > the expected 6.
> > > >
> > > > ​Here are the interesting parts of the configuration:
> > > > upstream php-fpm {
> > > > server : down;
> > > > server : down;
> > > > [...]
> > > > server :;
> > > > server :;
> > > > server :;
> > > > server :;
> > > > server :;
> > > > server :;
> > > > keepalive 128;
> > > > }
> > > >
> > > > ​server {
> > > > set $fpm_pool "php-fpm$fpm_pool_ID";
> > > > [...]
> > > > location ~ \.php$ {
> > > > [...]
> > > > fastcgi_read_timeout 600;
> > > > fastcgi_keep_conn on;
> > > > fastcgi_index index.php;
> > > >
> > > > include fastcgi_params;
> > > > fastcgi_param SCRIPT_FILENAME
> > > > $document_root$fastcgi_script_name;
> > > > [...]
> > > > fastcgi_pass $fpm_pool;
> > > > }
> > > > }
> > > >
> > > > ​The question is:
> > > > php-fpm being an upstream group name, how come has it been tried as a
> > > > domain name in the end?
> > > > Stated otherwise, is this because the upstream group is considered
> > > 'down',
> > > > thus somehow removed from the possibilities, and nginx trying one
> last
> > > time
> > > > the name as a domain name to see if something answers?
> > > > This 7th request is definitely strange to my point of view. Is it a
> bug
> > > or
> > > > a 

[nginx] Set UDP datagram source address (ticket #1239).

2017-04-18 Thread Roman Arutyunyan
details:   http://hg.nginx.org/nginx/rev/dbb0c854e308
branches:  
changeset: 6980:dbb0c854e308
user:  Roman Arutyunyan 
date:  Tue Apr 11 16:41:53 2017 +0300
description:
Set UDP datagram source address (ticket #1239).

Previously, the source IP address of a response UDP datagram could differ from
the original datagram destination address.  This could happen if the server UDP
socket is bound to a wildcard address and the network interface chosen to output
the response packet has a different default address than the destination address
of the original packet.  For example, if two addresses from the same network are
configured on an interface.

Now source address is set explicitly if a response is sent for a server UDP
socket bound to a wildcard address.

diffstat:

 auto/unix   |  13 +
 src/os/unix/ngx_udp_sendmsg_chain.c |  90 +
 2 files changed, 103 insertions(+), 0 deletions(-)

diffs (130 lines):

diff -r ef935cd7ed8d -r dbb0c854e308 auto/unix
--- a/auto/unix Tue Apr 18 13:01:19 2017 +0300
+++ b/auto/unix Tue Apr 11 16:41:53 2017 +0300
@@ -394,6 +394,19 @@ ngx_feature_test="setsockopt(0, IPPROTO_
 . auto/feature
 
 
+# BSD way to set IPv4 datagram source address
+
+ngx_feature="IP_SENDSRCADDR"
+ngx_feature_name="NGX_HAVE_IP_SENDSRCADDR"
+ngx_feature_run=no
+ngx_feature_incs="#include 
+  #include "
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="setsockopt(0, IPPROTO_IP, IP_SENDSRCADDR, NULL, 0)"
+. auto/feature
+
+
 # Linux way to get IPv4 datagram destination address
 
 ngx_feature="IP_PKTINFO"
diff -r ef935cd7ed8d -r dbb0c854e308 src/os/unix/ngx_udp_sendmsg_chain.c
--- a/src/os/unix/ngx_udp_sendmsg_chain.c   Tue Apr 18 13:01:19 2017 +0300
+++ b/src/os/unix/ngx_udp_sendmsg_chain.c   Tue Apr 11 16:41:53 2017 +0300
@@ -203,6 +203,20 @@ ngx_sendmsg(ngx_connection_t *c, ngx_iov
 ngx_err_t  err;
 struct msghdr  msg;
 
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
+
+#if (NGX_HAVE_IP_SENDSRCADDR)
+u_char msg_control[CMSG_SPACE(sizeof(struct in_addr))];
+#elif (NGX_HAVE_IP_PKTINFO)
+u_char msg_control[CMSG_SPACE(sizeof(struct in_pktinfo))];
+#endif
+
+#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
+u_char msg_control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
+#endif
+
+#endif
+
 ngx_memzero(, sizeof(struct msghdr));
 
 if (c->socklen) {
@@ -213,6 +227,82 @@ ngx_sendmsg(ngx_connection_t *c, ngx_iov
 msg.msg_iov = vec->iovs;
 msg.msg_iovlen = vec->count;
 
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
+
+if (c->listening && c->listening->wildcard && c->local_sockaddr) {
+
+#if (NGX_HAVE_IP_SENDSRCADDR)
+
+if (c->local_sockaddr->sa_family == AF_INET) {
+struct cmsghdr  *cmsg;
+struct in_addr  *addr;
+struct sockaddr_in  *sin;
+
+msg.msg_control = _control;
+msg.msg_controllen = sizeof(msg_control);
+
+cmsg = CMSG_FIRSTHDR();
+cmsg->cmsg_level = IPPROTO_IP;
+cmsg->cmsg_type = IP_SENDSRCADDR;
+cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
+
+sin = (struct sockaddr_in *) c->local_sockaddr;
+
+addr = (struct in_addr *) CMSG_DATA(cmsg);
+*addr = sin->sin_addr;
+}
+
+#elif (NGX_HAVE_IP_PKTINFO)
+
+if (c->local_sockaddr->sa_family == AF_INET) {
+struct cmsghdr  *cmsg;
+struct in_pktinfo   *pkt;
+struct sockaddr_in  *sin;
+
+msg.msg_control = _control;
+msg.msg_controllen = sizeof(msg_control);
+
+cmsg = CMSG_FIRSTHDR();
+cmsg->cmsg_level = IPPROTO_IP;
+cmsg->cmsg_type = IP_PKTINFO;
+cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
+
+sin = (struct sockaddr_in *) c->local_sockaddr;
+
+pkt = (struct in_pktinfo *) CMSG_DATA(cmsg);
+ngx_memzero(pkt, sizeof(struct in_pktinfo));
+pkt->ipi_spec_dst = sin->sin_addr;
+}
+
+#endif
+
+#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
+
+if (c->local_sockaddr->sa_family == AF_INET6) {
+struct cmsghdr   *cmsg;
+struct in6_pktinfo   *pkt6;
+struct sockaddr_in6  *sin6;
+
+msg.msg_control = _control6;
+msg.msg_controllen = sizeof(msg_control6);
+
+cmsg = CMSG_FIRSTHDR();
+cmsg->cmsg_level = IPPROTO_IPV6;
+cmsg->cmsg_type = IPV6_PKTINFO;
+cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
+
+sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
+
+pkt6 = (struct in6_pktinfo *) CMSG_DATA(cmsg);
+ngx_memzero(pkt6, sizeof(struct in6_pktinfo));
+pkt6->ipi6_addr = sin6->sin6_addr;
+}
+
+#endif
+}
+
+#endif
+
 eintr:
 
 n = sendmsg(c->fd, , 0);

Welcome to nginx on Debian!

2017-04-18 Thread xstation
Welcome to nginx on Debian! is the default  holding page

where is this stored on debian 8 jessie?

thankyou
xstation

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,273701,273701#msg-273701

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


[nginx] Core: removed extra ngx_alloc() and ngx_calloc() prototypes.

2017-04-18 Thread Sergey Kandaurov
details:   http://hg.nginx.org/nginx/rev/ef935cd7ed8d
branches:  
changeset: 6979:ef935cd7ed8d
user:  Sergey Kandaurov 
date:  Tue Apr 18 13:01:19 2017 +0300
description:
Core: removed extra ngx_alloc() and ngx_calloc() prototypes.

diffstat:

 src/core/ngx_palloc.h |  3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diffs (13 lines):

diff -r 9fb994513776 -r ef935cd7ed8d src/core/ngx_palloc.h
--- a/src/core/ngx_palloc.h Mon Apr 17 14:42:12 2017 +0300
+++ b/src/core/ngx_palloc.h Tue Apr 18 13:01:19 2017 +0300
@@ -72,9 +72,6 @@ typedef struct {
 } ngx_pool_cleanup_file_t;
 
 
-void *ngx_alloc(size_t size, ngx_log_t *log);
-void *ngx_calloc(size_t size, ngx_log_t *log);
-
 ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
 void ngx_destroy_pool(ngx_pool_t *pool);
 void ngx_reset_pool(ngx_pool_t *pool);
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: Редирект с одного порта на другой

2017-04-18 Thread alexandre_frolov
Большое спасибо, помогло!

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?21,273696,273699#msg-273699

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: Редирект с одного порта на другой

2017-04-18 Thread Andrey Kopeyko

alexandre_frolov писал 2017-04-18 08:34:
Нужно сделать так, чтобы HTTPS-сайт открывался и через стандартный порт 
443,

и через нестандартный, например, 8082. Подскажите, пожалуйста, можно ли
сделать нужный редирект с помощью nginx, и каким образом?


Добрый день, Александр!

Если вам нужны оба порта - то редирект не понадобится:

server {
listen  443 ssl;
listen  8082 ssl;
server_name www.example.com;
...
}


Если вам надо "собирать" всех на каком-то одном порту - понадобится 
описать 2 сервера:


server {
listen  443 ssl;
server_name www.example.com;
...
}
server {
listen  8082 ssl;
server_name www.example.com;
location / {
rewrite  ^/(.*)$  https://www.example.com/  permanent;
}
}


--
Best regards,
Andrey A. Kopeyko 
___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: Как правильно настроить nginx proxypass?

2017-04-18 Thread winmasta
Добрый день появилась новая проблема, понадобилось перенаправлять все
запросы на root.ru/register на root.ru/auth/register и прочие (имена взяты
для примера), кусок конфига ниже, но почему-то перенаправление не
происходит, подскажите в где ошибка ?

server {
listen 80;
#   return 301 https://$server_name$request_uri;
listen 443 ssl;
server_name server1.root.ru server2.root.ru server3.root.ru
root.ru;
ssl_certificate
/etc/letsencrypt/live/root.ru/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/keys/0005_key-certbot.pem;
ssl_protocols   TLSv1 TLSv1.1 TLSV1.2;
access_log  /var/log/nginx/root_proxy.log;
location /register {
proxy_pass http://192.168.1.28/auth/register;
}
location /login {
proxy_pass http://192.168.1.28/auth/login;
}
location /resetPass {
proxy_pass http://192.168.1.28/auth/resetPass;
}
location /checkDomain {
proxy_pass http://192.168.1.28/auth/checkDomain;
}
location /setPass {
proxy_pass http://192.168.1.28/auth/setPass;
}
location /logout {
proxy_pass http://192.168.1.28/auth/logout;
}
location / {
proxy_pass http://192.168.1.28;
}
}

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?21,273530,273697#msg-273697

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru