OpenResty入门

写一个小例子

编写nginx配置文件

        location /random {
            content_by_lua_file /usr/local/openresty/nginx/conf/lua/random.lua;
        }

编写random.lua文件

local args = ngx.req.get_uri_args()
local salt = args.salt
if not salt then
    ngx.exit(ngx.HTTP_BAD_REQUEST)
end

local string = ngx.md5(ngx.time() .. salt)
ngx.say(string)

检查语法

./nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf

重启nginx

./nginx -s reload -c /usr/local/openresty/nginx/conf/nginx.conf

测试一下

curl 127.0.0.1/random?salt=123                              

成功输出了随机字符串

ea14f7a36e29925f3e9e318128f989f7

猜你喜欢

转载自www.cnblogs.com/tangzhe/p/9563172.html