当前位置: 首页 > linux, nginx > 正文

nginx lua as http client

首先感谢agentzh的辛苦大作,这里使用了openresty的版本。

1. 编译openresty


wget http://openresty.org/download/ngx_openresty-1.2.8.6.tar.gz
tar xzvf ngx_openresty-1.2.8.6.tar.gz
cd ngx_openresty-1.2.8.6/
./configure --with-luajit
make
make install

2.获取lua http client


git clone https://github.com/liseen/lua-resty-http

3. nginx vhost配置

cat 2hei.net.conf

lua_package_path ‘/usr/local/openresty/lualib/resty/?.lua;;’;
server {
listen 80;
server_name 2hei.net;

location /http_clinet{
resolver 8.8.8.8;
default_type ‘text/plain’;
content_by_lua ‘
ngx.say(“url_params: “, ngx.var.arg_url)
local http = require “resty.http”
local hc = http:new()

local ok, code, headers, status, body = hc:request {
url = “http://2hei.net/test.html?url=”..ngx.var.arg_url,
method = “GET”,
}

ngx.say(ok)
ngx.say(code)
ngx.say(body)
‘;
}
}

本文固定链接: https://www.2hei.net/2013/09/17/nginx-lua-as-http-client/ | 2hei.net

该日志由 u2 于2013年09月17日发表在 linux, nginx 分类下,
原创文章转载请注明: nginx lua as http client | 2hei.net
关键字: ,

报歉!评论已关闭.