sailorproject / sailor

A Lua MVC Web Framework.
MIT License
924 stars 123 forks source link

It not works well with nginx startup script #42

Closed rming closed 8 years ago

rming commented 9 years ago

vhost.conf

...
root /home/vagrant/vagrant/wwwroot/file.proxy;
...

error.log

/usr/local/share/lua/5.1/sailor.lua:119: /root/themes/default/main.lp: Permission denied
stack traceback:
    [C]: in function 'assert'
    /usr/local/share/lua/5.1/sailor.lua:119: in function 'read_src'
    /usr/local/share/lua/5.1/sailor.lua:151: in function 'render'
    .../vagrant/vagrant/wwwroot/file.proxy/controllers/main.lua:4: in function <.../vagrant/vagrant/wwwroot/file.proxy/controllers/main.lua:3>
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/sailor.lua:302: in function 'handlefunc'
    /usr/local/share/lua/5.1/remy.lua:163: in function 'run'
    /usr/local/share/lua/5.1/sailor.lua:46: in function 'launch'
    /home/vagrant/vagrant/wwwroot/file.proxy/index.lua:2: in function 

It seems the web root was changed while reloading nginx configration with my nginx startup script. /etc/ini.d/nginx reload

It woks well when I use nginx -s reload to relod nginx.

felipedaragon commented 9 years ago

Are you doing it as root? Try sudo /etc/init.d/nginx reload

rming commented 9 years ago

gif

changerlove commented 9 years ago

Hey, I got the same problem before. And this is because sailor.lua cannot get the ROOT PATH sent by Nginx. I fixed it by these steps:

  1. make sure your nginx.conf or lua.conf in Nginx Conf dir has write the root path.
  2. edit the sailor.lua in the function sailor.set_application_path as below:
-- Stores the path of the application in sailor.path
function sailor.set_application_path(r)
    local dir = lfs.currentdir()
    if dir == '/' or not dir then
        local filename = r.uri:match( "([^/]+)$")
        sailor.path = r.filename:match("^@?(.-)/"..filename.."$")
    elseif r.document_root then
        sailor.path = r.document_root
    else
        sailor.path = dir
    end
end

It works.

And this is my lua.conf:

server {
    listen  80;
    server_name lua.xwg.cc;
    root /webroot/api/;

    location / {
        lua_need_request_body on;
        lua_code_cache off;
        content_by_lua_file /webroot/api/index.lua$1;
        index index.lua index.lp;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires 1h;
    }
}