lua_code_cache 说明

nginx+lua开发时因为已经加载进内存,修改lua脚本不会起作用,这样不方便调试。nginx配置中将lua_code_cache配置成on/off来控制是否关闭lua 的cache缓存,如果设置为off.则每次修改lua脚本都会重新加载新的lua代码,从而实现快速调试响应。同时状态为off时启动或重启nginx都会提示:nginx: [alert] lua_code_cache is off; this will hurt performance in /path/to/nginx.conf。因为这会影响nginx性能表现。

注意!!!!!! 开发调试的时候使用off, 线上运行时设置为on。

配置方式

在nginx.conf那里配置

lua_code_cache off;#调试模式(即关闭lua脚本缓存)

  1. events {
  2. worker_connections 1024;
  3. }
  4. http {
  5. include mime.types;
  6. default_type application/octet-stream;
  7. sendfile on;
  8. keepalive_timeout 65;
  9. server {
  10. listen 8081;
  11. location / {
  12. lua_code_cache off;#调试模式(即关闭lua脚本缓存)
  13. content_by_lua_file '/lua/hello.lua';
  14. }
  15. }

配置完了需要刷新配置文件

[root@zjj101 lua]# openresty -s reload