Openresty nginx重装无法正常工作? (lua文件中更新的变量为nil)

时间:2018-03-12 05:41:08

标签: nginx lua openresty

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

这是我的nginx conf的一部分:

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个新变量fileSaveListingPathfileSaveDetailPath&记录为fileSaveZoomPath的{​​{1}}。

删除了旧变量nil,但仍然可以记录。

我觉得也许是缓存?缓存已关闭,afaik。

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

fileSaveRootPath

从代码中可以看出,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 我尝试记录它,但由于某种原因仍然可以记录它。这是从服务器端btw,所以我不想简单地重启整个服务器。

PS: ngx.var.fileSaveRootPath对我不起作用。

一些错误日志:

nginx -s reload

1 个答案:

答案 0 :(得分:0)

找到答案here

这部分:The immediate consequence is that you can't use custom variables in an http block.

似乎我试图设置我自己的自定义变量,但你实际上不能在nginx conf文件中做到这一点。

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

PS:

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