• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

026_nginx引用lua遇到的坑

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
server {
    listen      80;
    listen      443 ssl;
    server_name www.jyall.com;
    access_log  /data/log/nginx/*.www.jyall.com.access.log ngx_main;
    error_log   /data/log/nginx/*.www.jyall.com.error.log;

    charset utf-8;
    underscores_in_headers on;

    ssl_certificate           ssl/jyall.crt;
    ssl_certificate_key       ssl/*.www.jyall.com-2018-07-29.key;
    ssl_session_timeout       5m;
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers on;

    error_page 400 401 402 403 404 406 = /error404.html;
    location = /error404.html {
        root /opt/nginx/html;
    }
    error_page 500 502 503 504 = /error500.html;
    location = /error500.html {
        root /opt/nginx/html;
    }

    location ~ ^/get_json {
       default_type application/json;
       return 200 '{"status":"success","result":"nginx json3"}';       #json测试
    }

}

二、

]$ sudo luarocks list
Installed rocks:
----------------
lua-resty-iputils
   0.3.0-1 (installed) - /usr/local/lib/luarocks/rocks
luasocket
   3.0rc1-2 (installed) - /usr/local/lib/luarocks/rocks
lyaml
   6.1.1-4 (installed) - /usr/local/lib/luarocks/rocks
]$ sudo luarocks remove luasocket
]$ sudo vim nginx.conf
error_log /data/log/nginx/error.log debug   #把debug日志打开
]$ sudo /opt/nginx/sbin/nginx -t
the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: [error] init_by_lua_file error: /opt/nginx/conf/lua/resty/influxdb.lua:9: module 'socket' not found:
    no field package.preload['socket']
    no file '/opt/nginx/conf/lua/socket.lua'
    no file './socket.lua'
    no file '/usr/local/share/luajit-2.0.4/socket.lua'
    no file '/usr/local/share/lua/5.1/socket.lua'
    no file '/usr/local/share/lua/5.1/socket/init.lua'
    no file '/opt/nginx/conf/lua/socket.so'
    no file './socket.so'
    no file '/usr/local/lib/lua/5.1/socket.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    /opt/nginx/conf/lua/resty/influxdb.lua:9: in main chunk
    [C]: in function 'require'
    /opt/nginx/conf/lua/init_by_lua.lua:25: in main chunk
configuration file /opt/nginx/conf/nginx.conf test failed
]$ sudo /opt/nginx/sbin/nginx -s reload   #但是照样可以reload,而且日志没有任何报错
]$ sudo /opt/nginx/sbin/nginx -d          #下边的原先为json改为json3后内存内容也进行了更新 
    location ~ ^/get_json {
       default_type application/json;
       return 200 '{"status":"success","result":"nginx json3"}';
    }
}
nginx: [error] init_by_lua_file error: /opt/nginx/conf/lua/resty/influxdb.lua:9: module 'socket' not found:
    no field package.preload['socket']
    no file '/opt/nginx/conf/lua/socket.lua'
    no file './socket.lua'
    no file '/usr/local/share/luajit-2.0.4/socket.lua'
    no file '/usr/local/share/lua/5.1/socket.lua'
    no file '/usr/local/share/lua/5.1/socket/init.lua'
    no file '/opt/nginx/conf/lua/socket.so'
    no file './socket.so'
    no file '/usr/local/lib/lua/5.1/socket.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    /opt/nginx/conf/lua/resty/influxdb.lua:9: in main chunk
    [C]: in function 'require'
    /opt/nginx/conf/lua/init_by_lua.lua:25: in main chunk

]$ sudo curl -H "Host:venus.jyall.com" "127.0.0.1/get_json"    #但实际curl的时候还是最老的内容
{"status":"success","result":"nginx json"}

总结:(1)打开nginx debug(2)然后sudo /opt/nginx/sbin/nginx -t进行测试查询是否有问题(有问题需要及时修复)。

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
编译lua可执行程序发布时间:2022-07-22
下一篇:
linuxnginx安装防火墙ngx_lua_waf发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap