port of nginx http request

812 views
Skip to first unread message

Vijay Panghal

unread,
Dec 1, 2014, 8:47:58 PM12/1/14
to openre...@googlegroups.com
Hi,

Is there any ngx lua api to extract the port from the http request.

e.g. in this http proxy request, api should return <port>
"GET https://<host>:<port>/uri?args HTTP/1.1"

I see ngx lua has api to return uri and host with ngx.var.uri and  ngx.var.host respectively.

Regards,
Vijay

Yichun Zhang (agentzh)

unread,
Dec 2, 2014, 4:17:19 PM12/2/14
to openresty-en
Hello!

On Mon, Dec 1, 2014 at 5:47 PM, Vijay Panghal wrote:
> Is there any ngx lua api to extract the port from the http request.
>
> e.g. in this http proxy request, api should return <port>
> "GET https://<host>:<port>/uri?args HTTP/1.1"
>

I think what you need is just the $server_port nginx variable:

http://nginx.org/en/docs/http/ngx_http_core_module.html#var_server_port

All the (indexed) nginx variables can be accessed from within Lua via
the ngx.var API:

https://github.com/openresty/lua-nginx-module#ngxvarvariable

Regards,
-agentzh

James Hurst

unread,
Dec 4, 2014, 8:45:37 PM12/4/14
to openre...@googlegroups.com
I think perhaps you're looking for ngx.var.server_port ?

With ngx.var.* [1] you can read/write to any Nginx variables [2], though you can only write to those which have already been defined.



--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages