1

My nginx server have two endpoint. /callback/model/ as one and second /execute I want to get the complete uri of callback endpoint with in my execute.

eg: {http://ip:port}/callback/model/ or {domain}/callback/model/

Initially i tried constructing the uri as below

ngx.var.scheme .. "://" .. ngx.var.host ..":31003" .. "/callback/model/"

It works most the cases . But fails if I have domain or if port changes

Is there some way which nginx know the host its deployed and port details ? My service is a dockerised nginx server.

Sarga
  • 149
  • 3
  • 16

1 Answers1

1

Nginx knows the IP address and port on which it get the request. You can try

ngx.var.scheme .. "://" .. ngx.var.server_addr .. ":" : ngx.var.server_port .. "/callback/model/"

although I don't know how would it work under dockerized environment.

Ivan Shatsky
  • 13,267
  • 2
  • 21
  • 37
  • Hi @Ivan Shatsky thanks for responding. Do you know whats the difference between $host and $server_addr ? – Sarga Jun 26 '20 at 21:22
  • @Sarga `$server_addr` is an IP address on which nginx is bound, read about `$host` variable and its difference from `$http_host` [here](https://stackoverflow.com/questions/15414810/whats-the-difference-of-host-and-http-host-in-nginx/15414811#15414811). – Ivan Shatsky Jun 26 '20 at 21:27
  • I am running a script that posts a request to my nginx on 127.0.0.1:8080/path the values i get in ngx.var.server_addr is not 127.0.0.1 . Is there a way to get the request ip address with in nginx in any of its vars? – Sarga Jun 26 '20 at 23:00