# Ngx\_conf\_t args count

**URL:** <https://www.ruby-forum.com/t/ngx-conf-t-args-count/238076>\
**Category:** NGINX\
**Created:** [December 15, 2013, 10:32pm UTC](https://www.ruby-forum.com/t/ngx-conf-t-args-count/238076 "2013-12-15T22:32:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [December 15, 2013, 10:32pm UTC](https://www.ruby-forum.com/t/ngx-conf-t-args-count/238076/1 "2013-12-15T22:32:00Z")

</div>

From Miller’s [Emiller’s Guide to Nginx Module Development – Evan Miller](http://www.evanmiller.org/nginx-modules-guide.html),  
section 5.2:

ngx\_http\_upstream\_hash(ngx\_conf\_t \*cf, ngx\_command\_t \*cmd, void \*conf)  
{  
ngx\_http\_upstream\_srv\_conf\_t \*uscf;  
ngx\_http\_script\_compile\_t sc;  
ngx\_str\_t \*value;  
ngx\_array\_t \*vars\_lengths, \*vars\_values;

```
value = cf->args->elts;

/* the following is necessary to evaluate the argument to "hash"

```

as a $variable \*/  
ngx\_memzero(&sc, sizeof(ngx\_http\_script\_compile\_t));

```
vars_lengths = NULL;
vars_values = NULL;

sc.cf = cf;
sc.source = &value[1];
...

```

}

How does one know that value[1] is valid? Shouldn’t cf-\>args-\>nelts be  
checked first? Or does ngx\_conf\_t always have at least two options?

Related: why was value[0] not chosen?

Jeff

---

<div class="post-metadata">

**Author:** ![Jeffrey\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Jeffrey\_W](https://www.ruby-forum.com/u/Jeffrey_W)\
**Post date:** [December 16, 2013, 8:15am UTC](https://www.ruby-forum.com/t/ngx-conf-t-args-count/238076/2 "2013-12-16T08:15:45Z")

</div>

On Sun, Dec 15, 2013 at 04:31:08PM -0500, Jeffrey W. wrote:

> }
> 
> How does one know that value[1] is valid? Shouldn’t cf-\>args-\>nelts be  
> checked first? Or does ngx\_conf\_t always have at least two options?  
> Related: why was value[0] not chosen?

value[0] is the directive name, “hash” in this case. It’s  
like argv[] in main().

The “hash” directive can be specified in the “upstream” context  
(NGX\_HTTP\_UPS\_CONF) and it takes exactly one argument (NGX\_CONF\_TAKE1).  
The generic configuration parser code ensures that the argument  
exists.

> **[Emiller’s Guide to Nginx Module Development](https://www.evanmiller.org/nginx-modules-guide.html#directives)**
>
> Ever wanted to extend Nginx’s functionality with custom C code? This is the comprehensive guide that you need. Maintained since 2007.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Jeffrey\_W](https://www.ruby-forum.com/u/Jeffrey_W)\
**Post date:** [December 16, 2013, 8:28am UTC](https://www.ruby-forum.com/t/ngx-conf-t-args-count/238076/3 "2013-12-16T08:28:01Z")

</div>

On Mon, Dec 16, 2013 at 2:15 AM, Ruslan E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > value = cf->args->elts;
> > ...
> > 
> > ```
> 
> (NGX\_HTTP\_UPS\_CONF) and it takes exactly one argument (NGX\_CONF\_TAKE1).  
> The generic configuration parser code ensures that the argument  
> exists.
> 
> [Emiller’s Guide to Nginx Module Development – Evan Miller](http://www.evanmiller.org/nginx-modules-guide.html#directives)  
> Ah, thanks. It makes perfect sense.

Jeff
