A Rate-Limiting HTTP Proxy(6)Cookie/HTTPS/TIMER

A Rate-Limiting HTTP Proxy(6)Cookie/HTTPS/TIMER

Cookie Operation
https://github.com/362228416/openresty-web-dev/tree/master/demo12
https://github.com/cloudflare/lua-resty-cookie

HTTPS
https://github.com/362228416/openresty-web-dev/tree/master/demo13

TIMER
https://github.com/362228416/openresty-web-dev/tree/master/demo14

NGX document
https://github.com/openresty/lua-nginx-module#nginx-api-for-lua

Package
try with the example of MD5
https://openresty.org/cn/using-luarocks.html
https://github.com/blunt-object/openresty-luarocks

Install lua ENV
http://sillycat.iteye.com/admin/blogs/2376002
https://www.lua.org/download.html

On MAC
>curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz
unzip the file
>make macosx test
>sudo make macosx install
Verify the installation
>lua -v
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio

Where is the file
>which lua
/usr/local/bin/lua


On CentOS
>curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz
unzip the file
http://jackatlinux.blogspot.com/2013/11/installing-lua-and-luarocks-in-centos.html
>make linux
Exception:
lua.c:82:31: fatal error:
readline/readline.h: No such file or directory
#include <readline/readline.h>

Solution:
>sudo yum install readline-devel
>make linux
>sudo make install
>lua -v
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio

>which lua
/usr/local/bin/lua

On RaspberryPi
>curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz
unzip the file
Same Exception as CentOS when I do
>make linux test
lua.c:82:31: fatal error: readline/readline.h: No such file or directory
#include <readline/readline.h>

Solution:
>sudo apt-get install libreadline-dev
>make linux test
>sudo make install

>lua -v
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio

>which lua
/usr/local/bin/lua


Install luarocks
On MAC
>wget http://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz
>./configure --prefix=/Users/carl/tool/luarocks-2.4.2
>make build
>sudo make install
Link the bin directory and add to PATH
Verify the installation
>luarocks help

On CentOS
>wget http://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz
>./configure --prefix=/home/ec2-user/tool/luarocks-2.4.2
>make build
>sudo make install
Lin the bin directory and add to PATH
>sudo ln -s /home/ec2-user/tool/luarocks-2.4.2 /opt/luarocks-2.4.2
>sudo ln -s /opt/luarocks-2.4.2 /opt/luarocks
>luarocks help

On RaspberryPI
>wget http://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz
>./configure --prefix=/home/carl/tool/luarocks-2.4.2 --with-lua=/usr/local
>make build
>sudo make install
>luarocks help

Search Package
>luarocks search vanilla

Search results:
===============


Rockspecs and source rocks:
---------------------------

vanilla
   0.1.0.rc4-1 (rockspec) - https://luarocks.org
   0.1.0.rc4-1 (src) - https://luarocks.org
   0.1.0.rc3-1 (rockspec) - https://luarocks.org
   0.1.0.rc3-1 (src) - https://luarocks.org
   0.1.0.rc2-1 (rockspec) - https://luarocks.org
   0.1.0.rc2-1 (src) - https://luarocks.org
   0.1.rc1-1 (rockspec) - https://luarocks.org
   0.1.rc1-1 (src) - https://luarocks.org
   0.0.1-1 (rockspec) - https://luarocks.org
   0.0.1-1 (src) - https://luarocks.org

Install Package on Local
>luarocks install json4lua --local

List the packages
>luarocks list

Installed rocks:
----------------

json4lua
   0.9.30-1 (installed) - /Users/carl/.luarocks/lib/luarocks/rocks

Install MD5 package
>sudo luarocks install md5

Update luarocks
>sudo luarocks install luarocks

Check path
> lua -e "print(package.cpath)"
/usr/local/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/loadall.so;./?.so

>lua -e "print(package.path)"
/usr/local/share/lua/5.3/?.lua;
/usr/local/share/lua/5.3/?/init.lua;
/usr/local/lib/lua/5.3/?.lua;
/usr/local/lib/lua/5.3/?/init.lua;
./?.lua;
./?/init.lua

>sudo find /usr/local -name md5
Password:
/usr/local/go/src/crypto/md5

>luarocks list

Installed rocks:
----------------
luarocks
   2.4.2-1 (installed) - /Users/carl/tool/luarocks-2.4.2/lib/luarocks/rocks
md5
   1.2-1 (installed) - /Users/carl/tool/luarocks-2.4.2/lib/luarocks/rocks

https://stackoverflow.com/questions/6803582/luajit-not-seeing-rocks-installed-by-luarocks
http://wgxsoft.blog.163.com/blog/static/17381917120146234053774/

Reinstall luarocks
>sudo ./configure --with-lua="/opt/openresty/luajit" --lua-suffix="jit" --with-lua-include="/opt/openresty/luajit/include/luajit-2.1”
>sudo make build
>sudo make install
>luarocks --version
/usr/local/bin/luarocks 2.4.2
LuaRocks main command-line interface

>luarocks list

Installed rocks:
----------------
md5
   1.2-1 (installed) - /usr/local/lib/luarocks/rocks

In my lua Code, I will do
local rocks = require "luarocks.loader"
local md5 = require “md5"

function _M
.index()
 
-- ngx.say(md5.sumhexa("testforfun"));

  ngx.say(
cjson.encode(users))end

It will work pretty well.

package.sh will compile all lua to binary
>cat package.sh
#!/usr/bin/env bash

rm -rf ./dist
mkdir -p dist/app/logs
cp -rf conf dist/app
cp -rf html dist/app
cp -rf lua dist/app
cp -rf lualib dist/app

luajit=/opt/openresty/luajit/bin/luajit

function compile() {
    for file in $1
    do
        if test -f $file
        then
            $luajit -b $file $file
        fi
    done
}

compile "./dist/app/lua/web/*"
compile "./dist/app/lua/*"


References:
https://github.com/362228416/openresty-web-dev/tree/master/demo12
https://github.com/362228416/openresty-web-dev/tree/master/demo13

package 1
https://my.oschina.net/362228416/blog/846741
https://luarocks.org/
https://openresty.org/cn/using-luarocks.html
http://blog.leanote.com/post/wechat-fee3/b06945bcb7cc
http://dhq.me/luarocks-a-deployment-and-management-system-for-lua-modules
https://segmentfault.com/a/1190000003920034

package 2
https://luarocks.org/#quick-start

lua notes
http://nanxiao.me/category/%E6%8A%80%E6%9C%AF/lua%E7%AC%94%E8%AE%B0/



你可能感兴趣的:(A Rate-Limiting HTTP Proxy(6)Cookie/HTTPS/TIMER)