Set up the repository
nginx2root is the name of three nginx vulnerabilities fixed upstream in nginx 1.30.7 and 1.31.9 on 2026-11-18: CVE-2026-123007 (HTTP/2), CVE-2026-123634 (resolver) and CVE-2026-113425 (mail proxy).
Amazon Linux is not listed: Amazon already ships the fixed nginx 1.30.7. On Amazon Linux 2 install it with: amazon-linux-extras install nginx1
“Fixed” keeps your distribution's nginx version and adds only the nginx2root fixes to it, so it is a drop-in update. “Stable” is nginx 1.30.7. On Ubuntu 22.04 and 24.04, Debian 12 and 13 and Enterprise Linux 8, 9 and 10 it is nginx.org's own package: it is NOT a drop-in replacement, because its package layout differs from your distribution's (a single nginx package, configuration in /etc/nginx/conf.d), and the script only switches to it when you run it with --switch. On the other releases it is Clouding.io's build of nginx 1.30.7 with your distribution's own package names and layout, and the script upgrades the installed packages in place.
Ubuntu 22.04 LTS (Jammy): the nginx version of the distribution, with only the nginx2root fixes (CVE-2026-123007, CVE-2026-123634, CVE-2026-113425) backported by Clouding.io. Configuration files, modules and layout stay as they are.
It replaces your distribution's nginx packages with nginx.org's nginx 1.30.7, so it changes your installation. Nothing happens without --switch.
- First it saves /etc/nginx to /root/nginx-before-switch-<timestamp>.tgz and the list of installed nginx packages and versions to /root/nginx-before-switch-<timestamp>.pkgs.
- Then it removes the distribution's nginx packages (nginx* and libnginx-mod* on APT; nginx* but never nginx-filesystem on RPM, using dnf's own resolution, shown first) and installs nginx from this mirror. If removing them would also remove other packages, it stops without changing anything. The distribution's modules (libnginx-mod-*, nginx-mod-*) are not carried over. For each one the script says whether nginx.org has an equivalent (nginx-module-geoip, nginx-module-image-filter, nginx-module-njs, nginx-module-perl, nginx-module-xslt), how to install it and which load_module line to add; stream and mail are built into nginx.org's nginx, and the other modules (for example echo, headers-more, lua, geoip2, subs-filter) have no nginx.org equivalent.
- Then every file that existed under /etc/nginx before the switch is restored from the backup, so your configuration ends up exactly as it was (nginx.conf, conf.d, sites-available / sites-enabled, mime.types, fastcgi_params, ...). Where nginx.org's package had replaced a file, its own copy is kept next to it as <name>.nginx-org (for example /etc/nginx/nginx.conf.nginx-org). Files that nginx.org added and that did not exist before stay, except conf.d/default.conf: if you had none, nginx.org's is renamed to default.conf.nginx-org, so your configuration loads exactly what it loaded before. A link that points to something the switch removed (for example modules-enabled links to the distribution's modules) is not restored.
- It runs nginx -t. If the test fails, it prints the error, restores the whole backup, reinstalls the recorded distribution packages (it prints the exact command and runs it) and exits with status 1. If the test passes and nginx was running before, it stops every old nginx process (the service manager's stop, then QUIT to the masters and to orphan workers, TERM after 10 seconds, KILL as a last resort), starts nginx again and checks that the master runs the installed binary (not a deleted one) and that the parent of every worker is that master (an unreadable binary is treated as unknown, never as success); if that fails it prints an error and exits with status 1 without rolling back. If nginx was not running before, it is not started. Only the package's own nginx (its binary, normally /usr/sbin/nginx) is stopped and restarted: processes of other nginx-derived products are listed as foreign and left untouched; if a master whose binary cannot be read names no path in its title while another nginx binary is present, the script stops before any package change and asks you to stop that nginx yourself.
To go back to the distribution's packages later (the backup path is printed at the end of the script; use your own timestamp):
APT source file
# nginx-repos.clouding.io: nginx (fixed) - Ubuntu 22.04 LTS (Jammy) deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-repos.clouding.io.gpg] https://nginx-repos.clouding.io/ubuntu jammy fixed
Upgrade script (copy & paste as root)
#!/bin/sh
# nginx-repos.clouding.io - Upgrade the installed nginx packages to the nginx2root-fixed builds for Ubuntu 22.04 LTS (Jammy)
set -e
export LC_ALL=C DEBIAN_FRONTEND=noninteractive
[ "$(id -u)" = 0 ] || { echo 'Run this script as root.'; exit 1; }
CODENAME=$( (. /etc/os-release 2>/dev/null; echo "${VERSION_CODENAME:-}") )
[ -n "$CODENAME" ] || CODENAME=$(lsb_release -sc 2>/dev/null || true)
[ -n "$CODENAME" ] || CODENAME=$(sed -n "s/^DISTRIB_CODENAME=//p" /etc/lsb-release 2>/dev/null || true)
[ -n "$CODENAME" ] || CODENAME=$(sed -n "s/^VERSION=\"[0-9.]* (\([a-z]*\))\"$/\1/p" /etc/os-release 2>/dev/null || true)
[ "$CODENAME" = 'jammy' ] || { echo 'This system is not Ubuntu 22.04 LTS (Jammy): aborting.'; exit 1; }
# 0. prerequisites (only what is missing, from your distribution's own repositories)
NEED=
command -v curl >/dev/null 2>&1 || command -v wget >/dev/null 2>&1 || NEED="$NEED curl"
dpkg-query -W -f='${Status}\n' ca-certificates 2>/dev/null | grep -q ' installed$' || NEED="$NEED ca-certificates"
[ -x /usr/lib/apt/methods/https ] || NEED="$NEED apt-transport-https"
if [ -n "$NEED" ]; then
echo 'Installing the missing prerequisites from your distribution'\''s own repositories:' $NEED
{ apt-get update && apt-get install -y --no-install-recommends $NEED; } || { echo 'Could not install the prerequisites: your distribution'\''s own repositories are not reachable. Nothing has been changed.'; exit 1; }
echo 'Prerequisites installed:' $NEED
fi
WAS_RUNNING=0; RECPIDS=; EXTRABINS=; OURB=
NGXBIN=/usr/sbin/nginx; [ -x "$NGXBIN" ] || NGXBIN=$(command -v nginx 2>/dev/null || true)
set_ourbins() { # the binary paths that belong to the package being upgraded (or switched away from): /usr/sbin/nginx, the packages' own nginx binary, and their canonical paths
OURB=
for B in /usr/sbin/nginx $EXTRABINS; do
OURB="$OURB $B"; R=$(readlink -f "$B" 2>/dev/null) || R=
[ -z "$R" ] || OURB="$OURB $R"
done
}
nginx_scan() { # "PID kind" for every nginx-looking process, read from /proc (title in cmdline, binary in exe): kind = master | other (worker, cache, any nginx binary)
for D in /proc/[0-9]*; do
P=${D#/proc/}
C=$({ tr '\0' ' ' < "$D/cmdline"; } 2>/dev/null) || C=
E=$(readlink "$D/exe" 2>/dev/null) || E=
E=${E% \(deleted\)}
case "$C" in
("nginx: master process"*) echo "$P master"; continue;;
("nginx: "*) echo "$P other"; continue;;
esac
case "${E##*/}" in (nginx|nginx.*) echo "$P other";; esac
done
}
nginx_list() { # one "PID kind" per nginx-looking process: the /proc scan is the primary method; ps and pgrep are cross-checks that add what it missed
{ nginx_scan
if command -v ps >/dev/null 2>&1; then ps -eo pid,args 2>/dev/null | sed -n -e 's/^ *\([0-9][0-9]*\) *nginx: master.*/\1 master/p' -e 's/^ *\([0-9][0-9]*\) *nginx: [^m].*/\1 other/p'; fi
if command -v pgrep >/dev/null 2>&1; then pgrep -f '^nginx: master' 2>/dev/null | sed 's/$/ master/'; pgrep -f '^nginx: ' 2>/dev/null | sed 's/$/ other/'; fi
} | sort -n | awk '!seen[$1]++'
}
nginx_ppid() { sed -n "s/^PPid:[[:space:]]*//p" "/proc/$1/status" 2>/dev/null || true; } # parent PID (readable even when /proc/PID/exe is not)
nginx_class_one() { # $1 = PID, $2 = kind: prints "PID kind class binary" (class: ours | foreign | unk). Every case lives in a top-level function, never inside a $( ) (old bash 4.1/4.2 mis-parses case patterns there)
NP=$1; NK=$2
NE=$(readlink "/proc/$NP/exe" 2>/dev/null) || NE=; NE=${NE% \(deleted\)}
NC=$({ tr '\0' ' ' < "/proc/$NP/cmdline"; } 2>/dev/null) || NC=
set -f; set -- $NC; set +f; NA=${4:-}
NS=unk; NB=-
if [ -n "$NE" ]; then
NB=$NE
case " $OURB " in (*" $NE "*) NS=ours;; (*) NS=foreign;; esac
else
case "$NA" in
(/*) NB=$NA; case " $OURB " in (*" $NA "*) NS=ours;; (*) NS=foreign;; esac;;
esac
fi
echo "$NP $NK $NS $NB"
}
nginx_class_two() { # $1 = PID, $2 = kind, $3 = class of pass 1, $4 = binary: settles the "unk" ones (parent is one of our masters, or recorded as ours; else amb / foreign)
NP=$1; NK=$2; NS=$3; NB=$4
if [ "$NS" = unk ]; then
NPP=$(nginx_ppid "$NP"); NS=
case "$OMS" in (*" $NP "*) NS=ours;; esac
if [ -z "$NS" ] && [ -n "$NPP" ]; then case "$OMS" in (*" $NPP "*) NS=ours;; esac; fi
if [ -z "$NS" ]; then if [ "$NK" = master ]; then NS=amb; else NS=foreign; fi; fi
fi
echo "$NP $NK $NS $NB"
}
nginx_class() { # "PID kind class binary" per nginx-looking process. class: ours = the package's binary (exe, also "(deleted)"), or an unreadable exe whose title names that
# binary, or an unreadable exe whose parent is one of our masters / that was recorded as ours before the package change; foreign = any other binary (openresty,
# tengine, a build under /opt or /usr/local ...) or an unreadable worker nobody vouches for; amb = an unreadable master whose title names no path: it is ours only
# when no foreign nginx binary is known to the census
P1=$(nginx_list | while read -r P K; do [ -n "$P" ] || continue; nginx_class_one "$P" "$K"; done)
OMS=" $(echo "$P1" | awk '$2 == "master" && $3 == "ours" {print $1}' | tr '\n' ' ') $RECPIDS "
P2=$(echo "$P1" | while read -r P K S B; do [ -n "$P" ] || continue; nginx_class_two "$P" "$K" "$S" "$B"; done)
if [ -z "$(echo "$P2" | awk '$3 == "foreign" && $4 != "-" {print $1}')" ]; then echo "$P2" | awk '{ if ($3 == "amb") $3 = "ours"; print }'; else echo "$P2"; fi
}
nginx_snap() { CLS=$(nginx_class); } # one classification of the process table; c_* read it
c_all() { echo "$CLS" | awk '$3 == "ours" {print $1}'; }
c_masters() { echo "$CLS" | awk '$2 == "master" && $3 == "ours" {print $1}'; }
c_foreign() { echo "$CLS" | awk '$3 == "foreign" {print $1}'; }
c_amb() { echo "$CLS" | awk '$3 == "amb" {print $1}'; }
nginx_running() { nginx_snap; [ -n "$(c_all)" ]; }
census() { # $1 = heading: every nginx process OF THIS PACKAGE (master, worker, anything running its binary), then the foreign ones (listed, never touched)
nginx_snap; echo "$1"; CN=0; NONE='(none)'; UNR='unreadable'
for P in $(c_all); do
CN=1; echo " PID $P PPid $(nginx_ppid $P) $(readlink /proc/$P/exe 2>/dev/null || echo '?') $({ tr '\0' ' ' < /proc/$P/cmdline; } 2>/dev/null)"
done
[ "$CN" = 1 ] || echo " $NONE"
FP=$(c_foreign)
if [ -n "$FP" ]; then
echo 'Note: nginx processes that do NOT belong to this package (another product or build, e.g. openresty, tengine or a build under /opt or /usr/local) were found. They are not touched and not counted (PID, parent PID, binary or unreadable, title):'
for P in $FP; do echo " PID $P PPid $(nginx_ppid $P) $(readlink /proc/$P/exe 2>/dev/null || echo "$UNR") $({ tr '\0' ' ' < /proc/$P/cmdline; } 2>/dev/null)"; done
fi
}
sig() { # $1 = signal, $2 = PIDs
SIGW='sending'
echo " $SIGW $1: $(echo $2)"; kill -"$1" $2 2>/dev/null || true
}
wait_none() { # $1 = seconds: wait until none of OUR nginx processes is left (nothing of ours listens on the old sockets any more)
I=0; while nginx_running && [ "$I" -lt "$1" ]; do sleep 1; I=$((I+1)); done
! nginx_running
}
stop_old() { # stop EVERY old nginx process of this package: the service manager's stop, QUIT to the masters, QUIT to orphan workers, TERM after 10 s, KILL as last resort
if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then echo " systemctl stop nginx"; systemctl stop nginx || true
elif command -v service >/dev/null 2>&1 && [ -x /etc/init.d/nginx ]; then echo " service nginx stop"; service nginx stop || true
elif [ -x /etc/init.d/nginx ]; then echo " /etc/init.d/nginx stop"; /etc/init.d/nginx stop || true
fi
nginx_snap; MP=$(c_masters)
[ -z "$MP" ] || sig QUIT "$MP"
nginx_snap; MPS=" $(echo $MP) "; WP=
for X in $(c_all); do case "$MPS" in (*" $X "*) ;; (*) WP="$WP $X";; esac; done
[ -z "$WP" ] || sig QUIT "$WP"
wait_none 10 && return 0
sig TERM "$(c_all)"
wait_none 5 && return 0
sig KILL "$(c_all)"
wait_none 5
}
start_new() { # the service manager's start (systemd, service, init script); the package's nginx binary itself when there is none or it fails
if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then echo " systemctl start nginx"; systemctl start nginx && return 0
elif command -v service >/dev/null 2>&1 && [ -x /etc/init.d/nginx ]; then echo " service nginx start"; service nginx start && return 0
elif [ -x /etc/init.d/nginx ]; then echo " /etc/init.d/nginx start"; /etc/init.d/nginx start && return 0
fi
echo " $NGXBIN"; "$NGXBIN"
}
verify_new() { # 0 = a master of ours runs with the installed binary (its exe is readable, not deleted) and EVERY other process of ours is a child of such a master
WHY=; WHYX='installed binary:'; WHYU='binary unknown (/proc/PID/exe is not readable), it cannot be verified'; WHYP='its parent is not a current nginx master (old process, parent PID:'
nginx_snap
NGX=$(readlink -f "$NGXBIN" 2>/dev/null || echo "$NGXBIN")
MS=$(c_masters); MSP=" $(echo $MS) "
if [ -z "$MS" ]; then WHY='no nginx master process is running'; return 1; fi
for P in $(c_all); do
E=$(readlink /proc/$P/exe 2>/dev/null) || E=
case "$MSP" in
(*" $P "*) # a master: its binary must be readable and be the installed one
[ -n "$E" ] || { WHY="PID $P: $WHYU"; return 1; }
[ "$E" = "$NGX" ] || { WHY="PID $P: $E ($WHYX $NGX)"; return 1; };;
(*) # a worker or other process: its parent must be a current master (an orphan with PPid 1 is an old process); an unreadable exe is unknown, never success
PP=$(nginx_ppid $P)
case "$MSP" in (*" $PP "*) ;; (*) WHY="PID $P: $WHYP $PP)"; return 1;; esac
[ -z "$E" ] || [ "$E" = "$NGX" ] || { WHY="PID $P: $E ($WHYX $NGX)"; return 1; };;
esac
done
return 0
}
foreign_hint() { # a foreign nginx-derived process may be what keeps ours from starting (port 80/443)
nginx_snap; FP=$(c_foreign)
[ -z "$FP" ] || echo 'Another nginx-derived program is running. If it holds port 80/443 the new nginx cannot start: stop it or change its ports, then start nginx. PID(s):' "$(echo $FP)"
}
serve_new() { # nginx was running before the package change: stop every old process of ours, start the new binary, verify; 1 = it did not work (never a package rollback)
echo 'nginx was running before: stopping every old nginx process (master and workers) and starting the new binary:'
if ! stop_old; then nginx_snap; echo 'ERROR: these old nginx processes could not be stopped:' "$(echo $(c_all))"; echo 'The configuration test (nginx -t) passed, so nothing was rolled back: fix this by hand (kill -9 PID for the old processes, then systemctl start nginx, service nginx start or nginx).'; return 1; fi
if ! start_new; then echo 'ERROR: nginx could not be started with the new binary (check the nginx error log).'; foreign_hint; echo 'The configuration test (nginx -t) passed, so nothing was rolled back: fix this by hand (kill -9 PID for the old processes, then systemctl start nginx, service nginx start or nginx).'; return 1; fi
I=0; while ! verify_new && [ "$I" -lt 10 ]; do sleep 1; I=$((I+1)); done
if verify_new; then
echo 'OK: the nginx master runs the installed binary and every worker belongs to it. Master PID(s):' "$(echo $(c_masters))"
"$NGXBIN" -v 2>&1
return 0
fi
echo 'ERROR: nginx is not serving with the new binary:' "$WHY"; foreign_hint; echo 'The configuration test (nginx -t) passed, so nothing was rolled back: fix this by hand (kill -9 PID for the old processes, then systemctl start nginx, service nginx start or nginx).'
return 1
}
# 1. nginx-repos.clouding.io.gpg + nginx-repos.clouding.io.list
mkdir -p /usr/share/keyrings
if command -v curl >/dev/null 2>&1; then curl -fsSL https://nginx-repos.clouding.io/nginx-repos.clouding.io.gpg -o /usr/share/keyrings/nginx-repos.clouding.io.gpg.new
else wget -q -O /usr/share/keyrings/nginx-repos.clouding.io.gpg.new https://nginx-repos.clouding.io/nginx-repos.clouding.io.gpg; fi
mv /usr/share/keyrings/nginx-repos.clouding.io.gpg.new /usr/share/keyrings/nginx-repos.clouding.io.gpg && chmod 644 /usr/share/keyrings/nginx-repos.clouding.io.gpg
cat > /etc/apt/sources.list.d/nginx-repos.clouding.io.list <<'NGINXREPOS_EOF'
# nginx-repos.clouding.io: nginx (fixed) - Ubuntu 22.04 LTS (Jammy)
deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-repos.clouding.io.gpg] https://nginx-repos.clouding.io/ubuntu jammy fixed
NGINXREPOS_EOF
apt-get update
# 2. Planned upgrades (only already installed packages)
PKGS=$(dpkg-query -W -f='${db:Status-Abbrev} ${Package}\n' 'nginx*' 'libnginx-mod*' 2>/dev/null | awk '$1 ~ /^ii/ {print $2}' | sort -u)
[ -n "$PKGS" ] || { echo 'No installed nginx packages were found: nothing to upgrade.'; exit 0; }
OLDVERS=$(dpkg-query -W -f='${Package}=${Version} ' $PKGS)
show_rollback() {
echo " apt-get install --allow-downgrades $OLDVERS"
}
SIM=$(apt-get -s -o Dpkg::Options::=--force-confold install --only-upgrade --no-remove --no-install-recommends $PKGS 2>&1) || { echo "$SIM"; echo 'apt cannot upgrade these packages without removals or conflicts: aborting, nothing was changed.'; exit 1; }
if echo "$SIM" | grep -qE "^(Remv|Purg) "; then echo "$SIM" | grep -E "^(Remv|Purg) "; echo 'apt would remove packages: aborting, nothing was changed.'; exit 1; fi
DOWN=0
echo "$SIM" | sed -n "s/^Inst \([^ ]*\) \[\([^]]*\)\] (\([^ ]*\) .*/\1 \2 \3/p" > /tmp/nginx-repos-plan.$$
while read -r PKG OLD NEW; do if dpkg --compare-versions "$NEW" lt "$OLD"; then echo "DOWNGRADE $PKG $OLD -> $NEW"; DOWN=1; fi; done < /tmp/nginx-repos-plan.$$
[ "$DOWN" = 0 ] || { rm -f /tmp/nginx-repos-plan.$$; echo 'apt would downgrade packages: aborting, nothing was changed.'; exit 1; }
if [ ! -s /tmp/nginx-repos-plan.$$ ]; then rm -f /tmp/nginx-repos-plan.$$; echo 'Everything is already up to date.'; exit 0; fi
echo 'Planned upgrades:'; cat /tmp/nginx-repos-plan.$$; rm -f /tmp/nginx-repos-plan.$$
# 3. upgrade
set_ourbins
census 'nginx processes running before the package change (PID, parent PID, binary - ? = unreadable -, title):'
nginx_snap; AMB=$(c_amb)
if [ -n "$AMB" ]; then echo 'ERROR: an nginx master whose binary cannot be read and whose title names no path is running, and another nginx binary is present on this host, so it cannot be told whose nginx it is. Nothing has been changed. Stop that nginx yourself and run this script again. PID(s):' "$(echo $AMB)"; exit 1; fi
nginx_running && WAS_RUNNING=1 # anything of OUR nginx running now? then the new binary must serve afterwards
RECPIDS=$(echo $(c_all))
if ! apt-get -y -o Dpkg::Options::=--force-confold install --only-upgrade --no-remove --no-install-recommends $PKGS; then echo 'The package upgrade failed. To roll back, run:'; show_rollback; exit 1; fi
# 4. nginx -t + make the new binary serve
census 'nginx processes after the package change (PID, parent PID, binary - ? = unreadable -, title):'
echo 'Testing the nginx configuration and, if nginx was running, making the new binary serve'
FAILED=0
if [ -x "$NGXBIN" ]; then
if "$NGXBIN" -t; then
if [ "$WAS_RUNNING" = 1 ]; then serve_new || exit 1
else echo 'nginx was not running before: not starting it.'; fi
else FAILED=1; fi
fi
if [ "$FAILED" != 0 ]; then echo 'The nginx configuration test (nginx -t) failed with the new packages. To roll back, run:'; show_rollback; exit 1; fi
echo 'Done.'
The script only upgrades nginx packages that are already installed (names starting with nginx or libnginx-mod). It never installs new packages, never removes packages and never downgrades: it simulates the upgrade first and stops if apt would remove or downgrade anything. Existing configuration files are kept. Afterwards it tests the configuration (nginx -t). If nginx was running, it stops every old nginx process (masters and workers: a reload would keep the old, vulnerable code in memory), starts nginx with the new binary and checks that the master runs the installed binary and every worker belongs to it; if nginx was not running it is not started. Only this package's own nginx is touched: processes of other nginx-derived programs (openresty, tengine, your own build) are listed as foreign and left alone. If nothing is installed, or everything is already up to date, it says so and exits. If a download tool (curl or wget), the CA certificates or, on old APT, apt-transport-https are missing, the script first installs exactly those from your distribution's own repositories and prints what it installed; if they cannot be installed it stops before changing anything.