You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apisix.apache.org by hui li <yo...@apache.org> on 2020/04/20 07:48:43 UTC

How to create new built-in variables of nginx on openresty?

Because when we use apisix, there are certain requirements for the format
of access.log, and the format needs to be similar to the following:
[$ http_host] [$ route_id] [$ upstream_id] [$ uri] [$ scheme] [rsp_st: $
status] [ups_st: $ upstream_status]
For example, route_id is the id of the route object. This kind of data is
not the default built-in variable of nginx. How can I create the built-in
variable nginx of route_id?

Re: How to create new built-in variables of nginx on openresty?

Posted by YuanSheng Wang <me...@apache.org>.
On Mon, Apr 20, 2020 at 4:19 PM hui li <yo...@apache.org> wrote:

> In the past, a new built-in nginx variable was implemented through the
> nginx c module
> For example, define the ngx_http_variable_t nginx built-in variable on the
> nginx module, and then set the nginx built-in variable through various ffi
> callback methods
> The statement is as follows:
> {ngx_string ("app_id"), NULL,
> ngx_http_appid_variable, 0,
> NGX_HTTP_VAR_NOCACHEABLE, 0},


This method is more difficult and less flexible.


>
>
> YuanSheng Wang <me...@apache.org> 于2020年4月20日周一 下午4:05写道:
>
> > > How can I create the built-in variable nginx of route_id?
> >
> > 1. we can add a new variable `route_id` in nginx.conf .
> > 2. update it in Lua land.
> > 3. use it in access log format.
> >
> >
> > On Mon, Apr 20, 2020 at 3:48 PM hui li <yo...@apache.org> wrote:
> >
> > > Because when we use apisix, there are certain requirements for the
> format
> > > of access.log, and the format needs to be similar to the following:
> > > [$ http_host] [$ route_id] [$ upstream_id] [$ uri] [$ scheme] [rsp_st:
> $
> > > status] [ups_st: $ upstream_status]
> > > For example, route_id is the id of the route object. This kind of data
> is
> > > not the default built-in variable of nginx. How can I create the
> built-in
> > > variable nginx of route_id?
> > >
> >
> >
> > --
> > *MembPhis*
> > My github: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>


-- 
*MembPhis*
My github: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: How to create new built-in variables of nginx on openresty?

Posted by Ming Wen <we...@apache.org>.
Hi, hui,
you can also use `set` of Nginx[1], not only the C module.

[1] http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set

Thanks,
Ming Wen, Apache APISIX & Apache SkyWalking
Twitter: _WenMing


hui li <yo...@apache.org> 于2020年4月20日周一 下午4:19写道:

> In the past, a new built-in nginx variable was implemented through the
> nginx c module
> For example, define the ngx_http_variable_t nginx built-in variable on the
> nginx module, and then set the nginx built-in variable through various ffi
> callback methods
> The statement is as follows:
> {ngx_string ("app_id"), NULL,
> ngx_http_appid_variable, 0,
> NGX_HTTP_VAR_NOCACHEABLE, 0},
>
> YuanSheng Wang <me...@apache.org> 于2020年4月20日周一 下午4:05写道:
>
> > > How can I create the built-in variable nginx of route_id?
> >
> > 1. we can add a new variable `route_id` in nginx.conf .
> > 2. update it in Lua land.
> > 3. use it in access log format.
> >
> >
> > On Mon, Apr 20, 2020 at 3:48 PM hui li <yo...@apache.org> wrote:
> >
> > > Because when we use apisix, there are certain requirements for the
> format
> > > of access.log, and the format needs to be similar to the following:
> > > [$ http_host] [$ route_id] [$ upstream_id] [$ uri] [$ scheme] [rsp_st:
> $
> > > status] [ups_st: $ upstream_status]
> > > For example, route_id is the id of the route object. This kind of data
> is
> > > not the default built-in variable of nginx. How can I create the
> built-in
> > > variable nginx of route_id?
> > >
> >
> >
> > --
> > *MembPhis*
> > My github: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>

Re: How to create new built-in variables of nginx on openresty?

Posted by hui li <yo...@apache.org>.
In the past, a new built-in nginx variable was implemented through the
nginx c module
For example, define the ngx_http_variable_t nginx built-in variable on the
nginx module, and then set the nginx built-in variable through various ffi
callback methods
The statement is as follows:
{ngx_string ("app_id"), NULL,
ngx_http_appid_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0},

YuanSheng Wang <me...@apache.org> 于2020年4月20日周一 下午4:05写道:

> > How can I create the built-in variable nginx of route_id?
>
> 1. we can add a new variable `route_id` in nginx.conf .
> 2. update it in Lua land.
> 3. use it in access log format.
>
>
> On Mon, Apr 20, 2020 at 3:48 PM hui li <yo...@apache.org> wrote:
>
> > Because when we use apisix, there are certain requirements for the format
> > of access.log, and the format needs to be similar to the following:
> > [$ http_host] [$ route_id] [$ upstream_id] [$ uri] [$ scheme] [rsp_st: $
> > status] [ups_st: $ upstream_status]
> > For example, route_id is the id of the route object. This kind of data is
> > not the default built-in variable of nginx. How can I create the built-in
> > variable nginx of route_id?
> >
>
>
> --
> *MembPhis*
> My github: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: How to create new built-in variables of nginx on openresty?

Posted by YuanSheng Wang <me...@apache.org>.
> How can I create the built-in variable nginx of route_id?

1. we can add a new variable `route_id` in nginx.conf .
2. update it in Lua land.
3. use it in access log format.


On Mon, Apr 20, 2020 at 3:48 PM hui li <yo...@apache.org> wrote:

> Because when we use apisix, there are certain requirements for the format
> of access.log, and the format needs to be similar to the following:
> [$ http_host] [$ route_id] [$ upstream_id] [$ uri] [$ scheme] [rsp_st: $
> status] [ups_st: $ upstream_status]
> For example, route_id is the id of the route object. This kind of data is
> not the default built-in variable of nginx. How can I create the built-in
> variable nginx of route_id?
>


-- 
*MembPhis*
My github: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix