我正在尝试在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可以访问我计算机上的任何文件。我做错了什么?
更新:我用content_by_lua修复了它,里面有require
发布于 2016-10-16 17:04:02
我也遇到了这个问题,我通过添加以下内容解决了这个问题:
user root root;在我的nginx.conf中,因为我的lua脚本文件的用户和组是根用户。
你也可以改变你的lua脚本文件所有者。
发布于 2016-11-15 15:04:29
nginx通常有两个进程,一个是主进程,另一个是工作进程。由root用户运行的主进程,由nobody用户运行的辅助进程,因此您应该确保nobody用户可以读取/Users/lobster/documents/web_server/./lua/main.lua文件。
顺便说一句:
在nginx.conf中添加user root root;,工作进程将由根用户运行,所以他用另一种方法解决了您的问题。
https://stackoverflow.com/questions/28087228
复制相似问题