1

Using lua-nginx-module. And I'm unable to accomplish a thing wherein I'm want to modify the mtime of a file(touch.txt).

I tried using ..

os.execute("touch /app/directory/touch.txt")

and this

io.open('/app/directory/touch.txt','w').close()

But none of the above is working ..

Here how my nginx.conf looks like this ..

location / {
               auth_basic "Prohibited area";
               auth_basic_user_file /etc/apache2/.htpasswd;
               default_type 'text/plain';
               content_by_lua_block {
                  os.execute('/usr/bin/touch /app/directory/touch.txt')
                  local time = os.date("%m/%d/%Y %I:%M:%S %p")
                  ngx.say('Hello,world! '.. time)
               }
                proxy_redirect  off;
}

I see the time returned i.e (Hello,world! '.. time) in browser correctly but the mtime of touch.txt remain still the same.

Any things over here .. that I need to take care of.

Viren
  • 171
  • 1
  • 2
  • 10

1 Answers1

2
    location /lua {
      content_by_lua_block {
        local res = os.execute('/usr/bin/touch /tmp/touch.txt')
        local time = os.date("%m/%d/%Y %I:%M:%S %p")
        if res == 0 then
          ngx.header["Content-type"] = "text/plain"
          ngx.say('Hello,world! '.. time)
        else
          ngx.status = ngx.HTTP_NOT_FOUND
          ngx.header["Content-type"] = "text/plain"
          ngx.say('The world is doomed '.. time)
          ngx.say('because of  ' .. res)
        end
    }
Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11