Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

nginx Chroot Helper Script To Copy Libs To /lib64 and /usr/lib64

View nginx-chroot-helper.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#!/bin/bash
 
set -e
# Use this script to copy shared (libs) files to nginx chrooted
# jail server. This is tested on 64 bit Linux (Redhat and Friends only)
# ----------------------------------------------------------------------------
# Original Written by Vivek Gite <http://www.cyberciti.biz/>
# (c) 2006 nixCraft under GNU GPL v2.0+
# ----------------------------------------------------------------------------
# See url for usage:
# http://www.cyberciti.biz/faq/howto-run-nginx-in-a-chroot-jail/
# ----------------------------------------------------------------------------
 
sync_dependencies() {
local JAILROOT="$1"
local pFILE="$2"
 
local files=""
local _cp="/bin/cp"
 
files="$(ldd "$pFILE" | sed 's|^\s*\(.* => \)*\(.*\) (0x[0-9a-f]\+)$|\2|')"
 
for LIB in $files
do
LIBDIR="$(dirname "$LIB")"
[ -d "${JAILROOT}${LIBDIR}" ] || mkdir -vp "${JAILROOT}${LIBDIR}"
"${_cp}" -vf "$LIB" "${JAILROOT}${LIBDIR}"
done
 
# Works with 32 and 64 bit ld-linux
sldl="$(ldd "$pFILE" | grep 'ld-linux' | awk '{ print $1}')"
sldlsubdir="$(dirname "${sldl}")"
[ -d "${JAILROOT}${sldlsubdir}" ] || mkdir -vp "${JAILROOT}${sldlsubdir}"
[ -f "${JAILROOT}${sldl}" ] || "${_cp}" -vf "${sldl}" "${JAILROOT}${sldlsubdir}"
}
 
usage() {
echo "Syntax : $0 /var/chroot /usr/local/nginx/sbin/nginx" >&2
echo "Example: $0 /home/user /usr/bin/php5-cgi" >&2
exit 1
}
 
[ $# = 2 ] || usage
BASE="$1"
BINARY="$2"
[ -d "$BASE" ] || usage
[ -f "$BINARY" ] || usage
 
sync_dependencies "$BASE" "$BINARY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.