Skip to content

Instantly share code, notes, and snippets.

@simonkuang
Last active July 6, 2025 11:59
Show Gist options
  • Save simonkuang/87c89e18cdef2af841c8d036126a2089 to your computer and use it in GitHub Desktop.
Save simonkuang/87c89e18cdef2af841c8d036126a2089 to your computer and use it in GitHub Desktop.
自己构建一个 Openresty docker,给 openresty 加上 njs 的命令。
#!/bin/bash
OPENRESTY_VERSION=1.27.1.2
PWD=$(cd $(dirname "$0"); pwd)
docker build -f ${PWD}/Dockerfile -t simonkuang/openresty:bookworm-fat --build-arg OPENRESTY_VERSION=${OPENRESTY_VERSION} --build-arg IN_GFW=1 .
FROM openresty/openresty:bookworm-fat AS builder
USER root
ARG OPENRESTY_VERSION="1.27.1.2"
ARG NGINX_VERSION="1.27.1"
ARG IN_GFW
COPY misc/gfw.sh /root/docker-gfw.sh
RUN ( [ -n ${IN_GFW} ] && /bin/bash /root/docker-gfw.sh bookworm ) && \
apt-get update -y && apt-get install -y gcc make git libpcre3-dev zlib1g-dev libssl-dev libxml2-dev libxslt-dev libedit-dev && \
mkdir -p /data/soft/openresty && cd /data/soft && \
curl -Lo /data/soft/openresty-${OPENRESTY_VERSION}.tar.gz https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz && \
tar --strip-component=1 -C /data/soft/openresty -zxf /data/soft/openresty-${OPENRESTY_VERSION}.tar.gz && \
( [ -n ${IN_GFW} ] && /bin/bash /root/docker-gfw.sh git ) && \
git clone --depth=1 https://github.com/bellard/quickjs /data/soft/quickjs && \
cd /data/soft/quickjs && CFLAGS='-fPIC' make libquickjs.a && \
git clone --depth=1 https://github.com/nginx/njs.git /data/soft/njs && \
cd /data/soft/njs && \
./configure \
--cc-opt="-O -I/data/soft/quickjs" \
--ld-opt="-O -L/data/soft/quickjs" && \
make -j`nproc` && \
cp /data/soft/njs/build/njs /usr/bin/njs && \
cd /data/soft/openresty && \
./configure --add-dynamic-module="/data/soft/njs/nginx" \
--with-cc-opt="-I/data/soft/quickjs" \
--with-ld-opt="-L/data/soft/quickjs" && \
make -j`nproc` && \
mkdir -p /usr/local/openresty/nginx/modules && \
find /data/soft/openresty/build -type f -name "ngx_*_js_module.so" \
-exec cp "{}" /usr/local/openresty/nginx/modules/ \;
FROM openresty/openresty:bookworm-fat AS prod
COPY --from=builder /usr/bin/njs /usr/bin/njs
COPY --from=builder /usr/local/openresty/nginx/modules \
/usr/local/openresty/nginx/modules
#!/bin/bash
if [[ "x$1" == "xbookworm" ]]; then
cat <<EOF > /etc/apt/sources.list.d/debian.sources
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
# Suites: bookworm bookworm-updates bookworm-backports
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
# Suites: bookworm-security
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
fi
if [[ "x$1" == "xnoble" ]]; then
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
Types: deb-src
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb-src
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 预发布软件源,不建议启用
# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
fi
if [[ "x$1" == "xgit" ]]; then
git config --global url."https://ghfast.top/https://github.com/".insteadOf "https://github.com/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment