Openresty nginx重新加载不工作?(更新的变量在lua文件中为零)

Openresty nginx重新加载不工作?(更新的变量在lua文件中为零),nginx,lua,openresty,Nginx,Lua,Openresty,我目前正在将一些新变量传递到我的lua文件中,当我注销它们时,这些新变量似乎是nil,我删除了名为saveFileRootPath的旧变量,但旧变量仍然可以被记录 以下是我的nginx配置的一部分: location /fileupload { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_he

我目前正在将一些新变量传递到我的lua文件中,当我注销它们时,这些新变量似乎是
nil
,我删除了名为
saveFileRootPath
的旧变量,但旧变量仍然可以被记录

以下是我的nginx配置的一部分:

location /fileupload {
            if ($request_method = 'OPTIONS') {
              add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              #
              # Custom headers and headers various browsers *should* be OK with but aren't
              #
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,fileheader';
              #
              # Tell client that this pre-flight info is valid for 20 days
              #
              add_header 'Access-Control-Max-Age' 1728000;
              add_header 'Content-Type' 'text/plain; charset=utf-8';
              add_header 'Content-Length' 0;
              return 204;
            }
            if ($request_method = 'POST') {
              add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,fileheader';
              add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            }
            if ($request_method = 'GET') {
              add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,fileheader';
              add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            }
            default_type text/html;
            set $fileSaveListingPath "C:\\Services\\openresty\\html_ecomm\\files\\listing";
            set $fileSaveDetailPath "C:\\Services\\openresty\\html_ecomm\\files\\detail";
            set $fileSaveZoomPath "C:\\Services\\openresty\\html_ecomm\\files\\zoom";
            content_by_lua_file lua/fileupload.lua;
        }
添加了3个新变量
fileSaveListingPath
fileSaveDetailPath
fileSaveZoomPath
,它们记录为
nil

已删除旧变量
fileSaveRootPath
,但仍可记录

我觉得可能有个缓存?缓存已关闭,请注意

这是我的lua文件的上半部分:

local http = require "resty.http"
local upload = require "resty.upload"
local cjson = require "cjson"
local saveRootPath = ngx.var.fileSaveRootPath
ngx.log(ngx.ERR, "TEST: "..ngx.var.fileSaveRootPath )
local chunk_size = 4096
local form, err = upload:new(chunk_size)
if not form then
    ngx.log(ngx.ERR, "failed to new upload: ", err)
    ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end

form:set_timeout(1000)

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end
正如您从代码中看到的,
ngx.var.fileSaveRootPath
我试图记录它,但由于某些原因仍然可以记录它。这是从服务器端顺便说一句,所以我不想简单地重新启动整个服务器

附言:
nginx-s重新加载
对我不起作用

一些错误日志:

2018/03/12 11:42:45 [info] 10660#10372: *4506 client closed connection while waiting for request, client: 124.13.241.136, server: 0.0.0.0:16001
2018/03/12 11:44:40 [error] 10660#10372: *4508 lua entry thread aborted: runtime error: ./lua/fileupload.lua:9: attempt to concatenate field 'fileSaveListingPath' (a nil value)
stack traceback:
coroutine 0:
    ./lua/fileupload.lua: in function <./lua/fileupload.lua:1>, client: 124.13.241.136, server: db.hkltd.com, request: "POST /fileupload/ HTTP/1.1", host: "xxx.com:16003", referrer: "http://localhost:3000/catalogmanagement/8868"
2018/03/12 11:45:43 [info] 10660#10372: *4514 client closed connection while waiting for request, client: 124.13.241.136, server: 0.0.0.0:16003
2018/03/12 11:58:16 [error] 10660#10372: *4516 lua entry thread aborted: runtime error: ./lua/fileupload.lua:9: attempt to concatenate field 'fileSaveListingPath' (a nil value)
stack traceback:
coroutine 0:
    ./lua/fileupload.lua: in function <./lua/fileupload.lua:1>, client: 124.13.241.136, server: xxx.com, request: "POST /fileupload/ HTTP/1.1", host: "xxx:16003", referrer: "xxx.com:16003/catalogmanagement/8868"
2018/03/12 11:42:45[info]10660#10372:*4506客户端在等待请求时关闭连接,客户端:124.13.241.136,服务器:0.0.0.0:16001
2018/03/12 11:44:40[错误]10660#10372:*4508 lua条目线程中止:运行时错误:./lua/fileupload.lua:9:尝试连接字段“fileSaveListingPath”(零值)
堆栈回溯:
协同程序0:
/lua/fileupload.lua:在函数中,客户端:124.13.241.136,服务器:db.hkltd.com,请求:“POST/fileupload/HTTP/1.1”,主机:“xxx.com:16003”,推荐人:http://localhost:3000/catalogmanagement/8868"
2018/03/12 11:45:43[信息]10660#10372:*4514客户端在等待请求时关闭了连接,客户端:124.13.241.136,服务器:0.0.0.0:16003
2018/03/12 11:58:16[错误]10660#10372:*4516 lua条目线程中止:运行时错误:./lua/fileupload.lua:9:尝试连接字段“fileSaveListingPath”(零值)
堆栈回溯:
协同程序0:
./lua/fileupload.lua:在函数中,客户端:124.13.241.136,服务器:xxx.com,请求:“POST/fileupload/HTTP/1.1”,主机:“xxx:16003”,参考者:“xxx.com:16003/catalogmanagement/8868”
找到了答案

这一部分:
直接后果是不能在http块中使用自定义变量。

似乎我试图设置自己的自定义变量,但实际上在nginx conf文件afaik中无法这样做

我的解决方案是在lua文件中设置我的位置,一切都很好

附言:


nginx-s reload
正常工作。我添加了几个服务器条目,重新加载工作正常。

只是猜测-如果NGINX无法成功应用新配置,它将继续使用旧配置(保存在某处)。这可能解释了为什么您仍然可以看到旧的变量。请提供错误日志文件,这可能会有所帮助。感谢您的响应,但只有一个地方保存了nginx.conf(搜索了整个硬盘)。有什么想法吗?提供错误信息logs@AlexanderAltshuler添加了一些日志您是否使用Docker运行nginx?