无法配置 OIDC 与 lua nginx

正在按照以下博客(https://developers.redhat.com/blog/2018/10/08/configuring-nginx-keycloak-oauth-oidc/)设置 NGINX lua oidc。 以下是我的安装和设置,我无法运行下面的命令

使用 luarocks 安装所有 Lua 模块:

# luarocks 安装 lua-cjson
# luarocks 安装 lua-resty-openidc

结果:

[root@samplesys nginx-lua]# yum install luarocks
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.netdepot.com
 * epel: mirror.lax.genesisadaptive.com
 * extras: mirror.netdepot.com
 * updates: mirror.netdepot.com
Package luarocks-2.3.0-1.el7.x86_64 already installed and latest version
Nothing to do

[root@sample nginx-lua]# luarocks install lua-cjson
Warning: falling back to curl - install luasec to get native HTTPS support
Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org - Failed downloading https://luarocks.org/manifest-5.1 - /var/cache/luarocks/https___luarocks.org/manifest-5.1
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ - Failed downloading https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/manifest-5.1 - /var/cache/luarocks/https___raw.githubusercontent.com_rocks-moonscript-org_moonrocks-mirror_master_/manifest-5.1
Warning: Failed searching manifest: Failed extracting manifest file: failed extracting /var/cache/luarocks/http___luafr.org_moonrocks_/manifest-5.1.zip
Warning: Failed searching manifest: Failed extracting manifest file: failed extracting /var/cache/luarocks/http___luarocks.logiceditor.com_rocks/manifest-5.1.zip
找不到适用于 Lua 5.1  lua-cjson。
检查是否可用于其他 Lua 版本...
检查 Lua 5.2...
检查 Lua 5.3...
检查 Lua 5.4...

错误:找不到适用于 Lua 5.1 的查询结果。

[root@sample nginx-lua]# luarocks install lua-resty-openidc
Warning: falling back to curl - install luasec to get native HTTPS support
Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org - Failed downloading https://luarocks.org/manifest-5.1 - /var/cache/luarocks/https___luarocks.org/manifest-5.1
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ - Failed downloading https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/manifest-5.1 - /var/cache/luarocks/https___raw.githubusercontent.com_rocks-moonscript-org_moonrocks-mirror_master_/manifest-5.1
Warning: Failed searching manifest: Failed extracting manifest file: failed extracting /var/cache/luarocks/http___luafr.org_moonrocks_/manifest-5.1.zip
Warning: Failed searching manifest: Failed extracting manifest file: failed extracting /var/cache/luarocks/http___luarocks.logiceditor.com_rocks/manifest-5.1.zip
找不到适用于 Lua 5.1  lua-resty-openidc。
检查是否可用于其他 Lua 版本...
检查 Lua 5.2...
检查 Lua 5.3...
检查 Lua 5.4...

错误:找不到适用于 Lua 5.1 的查询结果。
点赞
用户4984564
用户4984564

这里有几件事情出了问题:

  1. 编译 nginx 并手动添加 lua-nginx-module 这种方式不是推荐的安装 openresty 的方法。引用 readme

强烈推荐使用 OpenResty 发行版,其中包括 Nginx、ngx_lua(这个模块)、LuaJIT,以及其他强大的 Nginx 模块和 Lua 库。

  1. 教程中使用的 Lua 版本似乎是 PUC Lua 5.1,这个版本现在已经不再流行了;人们使用 5.1 的原因是因为 LuaJIT 实现了那个版本。我不记得 openresty 目前还支持哪个版本,但更高版本主要是为了与 LuaJIT 兼容。

  2. 如果你使用的是 openresty 发行版,就不需要安装 lua-cjson,因为它已经包含在里面了(详见 readme)。

  3. 看一下你得到的错误信息 Failed fetching manifest for https://luarocks.org - Failed downloading https://luarocks.org/manifest-5.1,似乎 luarocks 无法下载清单文件,这可能是 luarocks.org 的临时问题(在我写这篇回答时它可以工作),或者是你的网络问题。尝试使用像 wget 或者 curl 这样的工具下载错误信息中的 URL,看看是否可行(curl 是否已安装?)。

2020-02-17 10:25:14