首页 > linux, nginx > nginx lua as http client

nginx lua as http client

2013年9月17日

首先感谢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)
‘;
}
}

分类: linux, nginx 标签: ,
本文的评论功能被关闭了.