lua 有现成的 io 操作api, 你可以直接用 lua 写文件
LubinLew

- Jan 4, 2022
- Joined Aug 17, 2020
可以参考一下我之前写的例子 https://blog.lubinlew.site/#/openresty/modules/lua-resty-upload ,主要是里面_download_file() 函数
- In luajit -j选项
LuaJIT 的 -j选项在说明里 https://luajit.org/running.html 只有下面这些选项
-jon — Turns the JIT compiler on (default).
-joff — Turns the JIT compiler off (only use the interpreter).
-jflush — Flushes the whole cache of compiled code.
-jv — Shows verbose information about the progress of the JIT compiler.
-jdump — Dumps the code and structures used in various compiler stages.但是我在项目https://github.com/starius/lua-lru 中看到
$ luajit -jp=v benchmark.lua lrucache
92% Compiled
8% Garbage Collector
这个-jp=v
是什么意思啊, 说明里没有啊, 好像可以显示代码有多少可以JIT 希望共享内存功能 可以增加一个获取 key 个数的接口
use bundle to compile the so, not only the nginx
增大 proxy_read_timeout 试试
location ~ \.php$ { root html; fastcgi_pass unix:///var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; header_filter_by_lua_block { local cookie = ngx.resp.get_headers()['Set-Cookie'] ---> cookie is a table ngx.log(ngx.ERR, table.concat(cookie, ',')) } }
应该是return 早于 realip模块执行
`
http {
access_log logs/access.log;server { listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1:81/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
}
server { listen 81; server_name localhost; location / { set_real_ip_from 127.0.0.1; real_ip_header X-Forwarded-For; real_ip_recursive on; access_by_lua_block { ngx.say(ngx.var.remote_addr) return ngx.exit(200) } } }
}
`
- In 共享内存
lua_shared_dict 只能在http{}块里定义, 你在server下定义共享内存, 是怎么定义的?
hackzhuyan 大佬那个assert没搞懂, 什么算assert ?
hackzhuyan ok, 明白了,谢谢大佬
xiaocang 谢谢大佬回复, 但是nginx-lua-moudle的test中很多都是
repeat_each(2);
plan tests => repeat_each() * (blocks() * 2);
(https://github.com/openresty/lua-nginx-module/blob/master/t/007-md5.t)这种还是看不懂,md5.t中总共7个block, 每个重复2次,那么总共测试14次才对,但是 plan test 中 block() 除了 repeat 又额外乘了2是为什么,
还有很多测试文件是这种的
repeat_each(2);
plan tests => repeat_each() * (blocks() * 3 + 4);
(https://github.com/openresty/lua-nginx-module/blob/master/t/009-log.t)
后面还加个数,就更不明白是怎么回事了我遇到的问题是 ab 与 openresty 在同一台机器上(CentOS7.8)运行会出握手失败, 另一台机器(CentOS8.2)跑ab 就没有问题
plan tests => repeat_each() * (blocks() * 6 + 4);
一个测试case就是一个测试block, 一个block由多个section组成,
repeat_each()返回之前设置的重复次数, 一个测试文件有2个测试case, 每个重复2次, 那就是总共测试4次,
那么后面block()函数返回的是什么值? plan tests 到底要做什么?(gdb) source luajit21.py
(gdb) lvm
No global L located (tried globalL and ngx_cycle)
(gdb)我在Centos 7上安装
测试脚本 use Test::Nginx::Socket::Lua;
yum install -y cpan
cpan Test::Nginx
提示我找不到 Test::Nginx::Socket::Lua 这个, 我又装了test-nginx
git clone https://github.com/agentzh/test-nginx.git
perl Makefile.PL
make
make install
又提示我找不到 Test::Base, 又装了 Test::Base
cpan Test::Base
又提示我找不到 Can't locate Digest/MD5.pm, 接着装
yum install -y perl-Digest-MD5
又提示我找不到Can't locate HTTP/Response.pm , 接着装
yum install -y perl-HTTP-*
最后成功了, 但是这样装对吗, 怎么会这么麻烦?
3Q~ 搞明白了