【问题标题】:Openresty content_by_lua_fileOpenresty content_by_lua_file
【发布时间】:2019-01-23 16:23:34
【问题描述】:

我正在尝试在 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

【问题讨论】:

  • 错误信息不够明确吗?它说它没有打开/读取相关文件的权限。修复文件的权限。请注意,以 root 身份登录时启动 Nginx 与以 root 身份运行 Nginx 不同。
  • Tye 绝对路径?

标签: nginx lua openresty


【解决方案1】:

我也遇到了这个问题,我通过添加解决了它:

user root root;

在我的nginx.conf 中,因为我的 lua 脚本文件的用户和组是 root。

您也可以更改您的 lua 脚本文件所有者。

【讨论】:

    【解决方案2】:

    nginx一般有2个进程,一个是master进程,一个是worker进程。主进程由root用户运行,工作进程由nobody用户运行,所以你应该确保nobody用户可以读取/Users/lobster/documents/web_server/./lua/main.lua文件。

    顺便说一句:

    rensike在nginx.conf中添加user root root;,worker进程将由root用户运行,所以他用另一种方式解决了你的问题。

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 2019-02-07
      • 2015-01-15
      • 1970-01-01
      • 2017-11-19
      • 2021-05-15
      • 1970-01-01
      • 2021-03-21
      • 2021-07-20
      相关资源
      最近更新 更多