Skip to content

Instantly share code, notes, and snippets.

@pietern
Created March 24, 2012 21:08
Show Gist options
  • Save pietern/2187930 to your computer and use it in GitHub Desktop.
Save pietern/2187930 to your computer and use it in GitHub Desktop.
Upgrades nginx to 1.1.17 on Micro Cloud Foundry
#!/bin/bash -e
lua_url="http://www.lua.org/ftp/lua-5.1.4.tar.gz"
lua_tgz="lua-5.1.4.tar.gz"
lua_dir="lua-5.1.4"
echo "Downloading and extracting ${lua_tgz}..."
[ ! -f "${lua_tgz}" ] && wget -q -O ${lua_tgz} ${lua_url}
rm -rf ${lua_dir}
tar zxf ${lua_tgz}
lua_openssl_url="https://github.com/zhaozg/lua-openssl/tarball/0.1.1"
lua_openssl_tgz="lua-openssl-0.1.1.tar.gz"
lua_openssl_dir="zhaozg-lua-openssl-5ecb647"
echo "Downloading and extracting ${lua_openssl_tgz}..."
[ ! -f "${lua_openssl_tgz}" ] && wget -q -O ${lua_openssl_tgz} ${lua_openssl_url}
rm -rf ${lua_openssl_dir}
tar zxf ${lua_openssl_tgz}
lua_cjson_url="http://www.kyne.com.au/~mark/software/lua-cjson-1.0.3.tar.gz"
lua_cjson_tgz="lua-cjson-1.0.3.tar.gz"
lua_cjson_dir="lua-cjson-1.0.3"
echo "Downloading and extracting ${lua_cjson_tgz}..."
[ ! -f "${lua_cjson_tgz}" ] && wget -q -O ${lua_cjson_tgz} ${lua_cjson_url}
rm -rf ${lua_cjson_dir}
tar zxf ${lua_cjson_tgz}
lua_base64_url="https://github.com/LuaDist/lbase64/tarball/5.1"
lua_base64_tgz="lua-base64.tar.gz"
lua_base64_dir="LuaDist-lbase64-c41bb50"
echo "Downloading and extracting ${lua_base64_tgz}..."
[ ! -f "${lua_base64_tgz}" ] && wget -q -O ${lua_base64_tgz} ${lua_base64_url}
rm -rf ${lua_base64_dir}
tar zxf ${lua_base64_tgz}
ngx_url="http://nginx.org/download/nginx-1.1.17.tar.gz"
ngx_tgz="nginx-1.1.17.tar.gz"
ngx_dir="nginx-1.1.17"
echo "Downloading and extracting ${ngx_tgz}..."
[ ! -f "${ngx_tgz}" ] && wget -q -O ${ngx_tgz} ${ngx_url}
rm -rf ${ngx_dir}
tar zxf ${ngx_tgz}
pcre_url="http://sourceforge.net/projects/pcre/files/pcre/8.21/pcre-8.21.tar.gz"
pcre_tgz="pcre-8.21.tar.gz"
pcre_dir="pcre-8.21"
echo "Downloading and extracting ${pcre_tgz}..."
[ ! -f "${pcre_tgz}" ] && wget -q -O ${pcre_tgz} ${pcre_url}
rm -rf ${pcre_dir}
tar zxf ${pcre_tgz}
ngx_upload_module_url="http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz"
ngx_upload_module_tgz="nginx_upload_module-2.2.0.tar.gz"
ngx_upload_module_dir="nginx_upload_module-2.2.0"
echo "Downloading and extracting ${ngx_upload_module_tgz}..."
[ ! -f "${ngx_upload_module_tgz}" ] && wget -q -O ${ngx_upload_module_tgz} ${ngx_upload_module_url}
rm -rf ${ngx_upload_module_dir}
tar zxf ${ngx_upload_module_tgz}
echo "Patching ${ngx_upload_module_tgz}..."
cd ${ngx_upload_module_dir}
patch -p1 <<EOS > /dev/null
diff -rupN nginx_upload_module-2.2.0/ngx_http_upload_module.c nginx_upload_module-2.2.0-mod/ngx_http_upload_module.c
--- nginx_upload_module-2.2.0/ngx_http_upload_module.c 2010-09-27 11:54:15.000000000 -0700
+++ nginx_upload_module-2.2.0-mod/ngx_http_upload_module.c 2011-08-13 16:54:51.703564429 -0700
@@ -688,7 +688,7 @@ ngx_http_upload_handler(ngx_http_request
ngx_http_upload_ctx_t *u;
ngx_int_t rc;
- if (!(r->method & NGX_HTTP_POST))
+ if (!(r->method & (NGX_HTTP_POST | NGX_HTTP_PUT)))
return NGX_HTTP_NOT_ALLOWED;
ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
EOS
cd ..
ngx_headers_more_url="https://github.com/agentzh/headers-more-nginx-module/tarball/v0.15rc3"
ngx_headers_more_tgz="headers-more-v0.15rc3.tar.gz"
ngx_headers_more_dir="agentzh-headers-more-nginx-module-5fac223"
echo "Downloading and extracting ${ngx_headers_more_tgz}..."
[ ! -f "${ngx_headers_more_tgz}" ] && wget -q -O ${ngx_headers_more_tgz} ${ngx_headers_more_url}
rm -rf ${ngx_headers_more_dir}
tar zxf ${ngx_headers_more_tgz}
ngx_devel_kit_url="https://github.com/simpl/ngx_devel_kit/tarball/v0.2.17rc2"
ngx_devel_kit_tgz="devel-kit-v0.2.17rc2.tar.gz"
ngx_devel_kit_dir="simpl-ngx_devel_kit-bc97eea"
echo "Downloading and extracting ${ngx_devel_kit_tgz}..."
[ ! -f "${ngx_devel_kit_tgz}" ] && wget -q -O ${ngx_devel_kit_tgz} ${ngx_devel_kit_url}
rm -rf ${ngx_devel_kit_dir}
tar zxf ${ngx_devel_kit_tgz}
ngx_lua_url="https://github.com/chaoslawful/lua-nginx-module/tarball/v0.4.1"
ngx_lua_tgz="nginx-lua.v0.4.1.tar.gz"
ngx_lua_dir="chaoslawful-lua-nginx-module-204ce2b"
echo "Downloading and extracting ${ngx_lua_tgz}..."
[ ! -f "${ngx_lua_tgz}" ] && wget -q -O ${ngx_lua_tgz} ${ngx_lua_url}
rm -rf ${ngx_lua_dir}
tar zxf ${ngx_lua_tgz}
prefix=/tmp/target
final=/var/vcap/packages/nginx
echo "Building ${lua_dir}..."
cd ${lua_dir}
make linux install INSTALL_TOP=${prefix}/lua
cd ..
echo "Building ${lua_openssl_dir}..."
cd ${lua_openssl_dir}
make all install PREFIX=${prefix}/lua CC="gcc \$(CFLAGS)"
cd ..
echo "Building ${lua_cjson_dir}..."
cd ${lua_cjson_dir}
make all install PREFIX=${prefix}/lua
cd ..
echo "Building ${lua_base64_dir}..."
cd ${lua_base64_dir}
make so LUA=${prefix}/lua/ LUAINC="\$(LUA)/include" LUABIN="\$(LUA)/bin" G=-fPIC
cp base64.so ${prefix}/lua/lib/lua/5.1
cd ..
echo "Building ${ngx_dir}..."
cd ${ngx_dir}
export LUA_LIB=${prefix}/lua/lib
export LUA_INC=${prefix}/lua/include
./configure \
--prefix=${final} \
--with-pcre=../${pcre_dir} \
--with-http_ssl_module \
--add-module=../${ngx_upload_module_dir} \
--add-module=../${ngx_headers_more_dir} \
--add-module=../${ngx_devel_kit_dir} \
--add-module=../${ngx_lua_dir}
make
/var/vcap/jobs/router/bin/nginx_ctl stop
mv ${final} ${final}.$(date +%s)
make install
mkdir -p ${final}/lib
cp ${prefix}/lua/lib/lua/5.1/* ${final}/lib
/var/vcap/jobs/router/bin/nginx_ctl start
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment