Skip to content

open-resty

nginx.conf: /usr/local/openresty/nginx/conf/nginx.conf

不要用 /etc/nginx!不要用 /etc/nginx!不要用 /etc/nginx!

lua 脚本: /usr/local/openresty/lualib/

自己的lua 放在 /etc/nginx/lua/,与官方的分开

logs: /usr/local/openresty/nginx/logs/

编译一个带 jwt 的 open-resty

Dockerfile
# -----------------------
# Builder stage (Debian Buster)
# -----------------------
FROM openresty/openresty:1.27.1.2-0-bookworm AS builder

# 安装 luarocks(Debian版OpenResty自带LuaJIT,但需要LuaRocks)
RUN apt-get update && apt-get install -y luarocks

# 安装 lua-resty-jwt(纯 Lua)
RUN luarocks install lua-resty-jwt

# 拷贝自定义 Lua 脚本(可选)
# COPY lua/ /etc/nginx/lua/

# -----------------------
# Runtime stage (Alpine)
# -----------------------
FROM openresty/openresty:1.27.1.2-alpine

# 从 builder 阶段拷贝 lua-resty-jwt 模块
COPY --from=builder /usr/local/share/lua/5.1 /usr/local/share/lua/5.1
COPY --from=builder /usr/local/lib/luarocks/rocks-5.1 /usr/local/lib/luarocks/rocks-5.1

# 拷贝自定义 Lua 脚本
# COPY --from=builder /etc/nginx/lua/ /etc/nginx/lua/

# 可选:拷贝 nginx 配置
# COPY nginx/nginx.conf /usr/local/openresty/nginx/conf/nginx.conf

# 暴露端口
EXPOSE 80

# 启动 OpenResty
CMD ["openresty", "-g", "daemon off;"]