私の問題
私はopenrestyを使って簡単なサーバーを構築しています。Openresty:luaでhttp呼び出しを行い、その解析結果を返します
このサーバーを呼び出すと、別のサーバーに別の呼び出しを行い、JSON結果をフェッチして処理し、解析結果を返します。
サーバーは、この質問の範囲外の理由でopenrestyで実装する必要があります。
コード
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;
}
}
エラーログ
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"
私の質問私はnginx
openrestyでLuaのコンテンツブロック内からのHTTP GETリクエストを作成するにはどうすればよい
?
私のコードで 'capture'を試みましたが、ローカルファイル(ログ参照)として扱われました。 –
これまでまたは今?私の代わりに 'location = /functions.json {'を使用してください。 –
ありがとう、私はサードパーティのhttpライブラリを使って解決しました:https://github.com/pintsized/lua-resty-http –