nginx - Openresty: Make an http call with lua and return its parsed result -
my problem
i using openresty build simple server.
upon calling server, should make call different server, fetch json result, process , return parsed result.
the server should implemented in openresty reasons beyond scope if question.
code
error_log /dev/stdout info; events { worker_connections 14096; } http { access_log off; lua_package_path ";;/usr/local/openresty/nginx/?.lua;"; server { keepalive_requests 100000; proxy_http_version 1.1; keepalive_timeout 10; location / { content_by_lua_block { res = ngx.location.capture('http://localhost:8080/functions.json') ngx.say(res.body) } } location /functions { root /usr/local/openresty/nginx/html/; } listen 0.0.0.0:80 default_server; } } error log
2017/09/11 08:27:49 [error] 7#7: *1 open() "/usr/local/openresty/nginx/htmlhttp://localhost:8080/functions.json" failed (2: no such file or directory), client: 172.17.0.1, server: , request: "get / http/1.1", subrequest: "http://localhost:8080/functions.json", host: "localhost:8080"
my question
how can make http request within lua content block in nginx openresty?
capture allow capture internal nginx locations , not absolute urls
error_log /dev/stdout info; events { worker_connections 14096; } http { access_log off; lua_package_path ";;/usr/local/openresty/nginx/?.lua;"; server { keepalive_requests 100000; proxy_http_version 1.1; keepalive_timeout 10; location / { content_by_lua_block { res = ngx.location.capture('/functions.json') ngx.say(res.body) } } location /functions.json { proxy_pass http://localhost:8080/functions.json; } location /functions { root /usr/local/openresty/nginx/html/; } listen 0.0.0.0:80 default_server; } }
Comments
Post a Comment