1. 程式人生 > >Lua指令碼傳送http請求時報錯: module 'socket' not found

Lua指令碼傳送http請求時報錯: module 'socket' not found

在使用nginx傳送http請求時報如下錯誤:

lua: ./socket/http.lua:11: module 'socket' not found:
	no field package.preload['socket']
	no file './socket.lua'
	no file '/usr/share/lua/5.1/socket.lua'
	no file '/usr/share/lua/5.1/socket/init.lua'
	no file '/usr/lib64/lua/5.1/socket.lua'
	no file '/usr/lib64/lua/5.1/socket/init.lua'
	no file './socket.so'
	no file '/usr/lib64/lua/5.1/socket.so'
	no file '/usr/lib64/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'require'
	./socket/http.lua:11: in main chunk
	[C]: in function 'require'
	lua.lua:3: in main chunk
	[C]: ?

具體解決辦法如下:

1、wget http://files.luaforge.net/releases/luasocket/luasocket/luasocket-2.0.2/luasocket-2.0.2.tar.gz

2、tar -xzvf luasocket-2.0.2.tar.gz

3、cd luasocket-2.0.2

4、進入目錄:luasocket-2.0.2,修改config檔案

LUAINC=-I/usr/local/nginx/lua/zhangys/luasocket-2.0.2/src

LUAINC=-I/usr/local/openresty/luajit/include/luajit-2.1

5、make & make install