026_nginx引用lua遇到的坑

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进行测试查询是否有问题(有问题需要及时修复)。