2

I am trying to create basic hello word page in OpenResty. It works fine if I use content_by_lua, however when I trying to use content_by_lua_file I've got this error:

2015/01/22 13:52:35 [alert] 2183#0: lua_code_cache is off; this will hurt performance in /Users/lobster/documents/web_server/conf/nginx.conf:10
2015/01/22 13:52:38 [error] 2223#0: *4 failed to load external Lua file "/Users/lobster/documents/web_server/./lua/main.lua": cannot open /Users/lobster/documents/web_server/./lua/main.lua: Permission denied, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"

But it doesn't have sense, because I can change /Users/lobster/documents/web_server/lua/main.lua file easily. There is my config:

worker_processes  1;
error_log logs/error.log;

events {
    worker_connections 1024;
}
http {
    lua_package_path '/lua/main.lua;';
    server {
    lua_code_cache off;
        listen 8080;
        location / {
            default_type 'text/plain';
            content_by_lua_file ./lua/main.lua;
        }
    }
}

I start nginx from root, so nginx can access any file on my computer. What I did wrong?

UPD: I fixed it using content_by_lua with require inside it

Lobster
  • 635
  • 2
  • 12
  • 30
  • 1
    Isn't the error message explicit enough? It says it doesn't have permission to open/read the file in question. Fix the permissions on the file. Note that starting Nginx while logged in as root is not the same as Nginx running as root. – Dayo Jan 22 '15 at 22:37
  • Tye **absolute path**? – fannheyward Mar 27 '15 at 07:41

2 Answers2

6

I also meet this problem and I solved it by adding :

user root root;

in my nginx.conf, because my lua script file's user and group is root.

Also u can change your lua script file owner.

Aamir
  • 16,329
  • 10
  • 59
  • 65
rensike
  • 69
  • 1
  • 2
5

The nginx normally have 2 processes, one is master process, another is a worker process. Master process run by root user, worker process run by nobody user, so you should make sure nobody user can read /Users/lobster/documents/web_server/./lua/main.lua file.

btw:

rensike add the user root root; in the nginx.conf, the worker process will run by root user, so he solved your problem in another way.

Nifle
  • 11,745
  • 10
  • 75
  • 100
iamdsy
  • 71
  • 1
  • 2