leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.14k stars 247 forks source link

Error when trying to run app on port 80, works fine on port 8080. #687

Closed punchmonster closed 4 years ago

punchmonster commented 4 years ago

When I run my app on port 8080 for development, everything works fine. When I run it on port 80 however I get this error? Makes it impossible to use for a production site.

content_by_lua(nginx.conf.compiled:24):2: in main chunk, client: 111.11.111.111, server: , request: "GET /article/compromise-death HTTP/1.1", host: "mywebsite.name"
2020/03/09 14:25:20 [error] 11797#0: *1 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/lapis/init.lua:15: module 'app' not found:
        no field package.preload['app']
        no file '/usr/local/openresty/site/lualib/app.ljbc'
        no file '/usr/local/openresty/site/lualib/app/init.ljbc'
        no file '/usr/local/openresty/lualib/app.ljbc'
        no file '/usr/local/openresty/lualib/app/init.ljbc'
        no file '/usr/local/openresty/site/lualib/app.lua'
        no file '/usr/local/openresty/site/lualib/app/init.lua'
        no file '/usr/local/openresty/lualib/app.lua'
        no file '/usr/local/openresty/lualib/app/init.lua'
        no file './app.lua'
        no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/app.lua'
        no file '/usr/local/share/lua/5.1/app.lua'
        no file '/usr/local/share/lua/5.1/app/init.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/app.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/app/init.lua'
        no file '/usr/local/openresty/site/lualib/app.so'
        no file '/usr/local/openresty/lualib/app.so'
        no file './app.so'
        no file '/usr/local/lib/lua/5.1/app.so'
        no file '/usr/local/openresty/luajit/lib/lua/5.1/app.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
        [C]: in function 'require'
        /usr/local/share/lua/5.1/lapis/init.lua:15: in function 'serve'
        content_by_lua(nginx.conf.compiled:24):2: in main chunk, client: 111.11.111.111, server: , request: "GET /article/compromise-death HTTP/1.1", host: "mywebsite.name"
punchmonster commented 4 years ago

for now I'm working around this by using

sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 8080

also tried copying the app.lua file like the person here did but that also did not work.

leafo commented 4 years ago

The port wouldn't have anything to do with that error. The error is saying it's not able to load your app.lua file after searching for it via the package path. Perhaps your changes to the port also changed the working directory, or the permissions the process has for reading files.

leafo commented 4 years ago

Going to close this since we don't really have any other info to work form.

Keep in mind 80 is a protected port by default, so generally you will need to configure your nginx process to have main process as root (or a user that has permissions) but have workers switch to another user.

But, the error you shared is from something else.