问题原文
原帖链接 · Viren · CC BY-SA 3.0
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.
已采纳解答
原帖链接 · Gerard H. Pille · CC BY-SA 3.0
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
}
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
