我正在尝试在 OpenResty 中创建基本的 hello word 页面。如果我使用 content_by_lua,它可以正常工作,但是当我尝试使用 content_by_lua_file 时,我遇到了这个错误:
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"
但这没有意义,因为我可以轻松更改 /Users/lobster/documents/web_server/lua/main.lua 文件。有我的配置:
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;
}
}
}
我从 root 启动 nginx,所以 nginx 可以访问我计算机上的任何文件。我做错了什么?
UPD:我使用 content_by_lua 修复了它,里面有 require