diff --git a/bin/compile b/bin/compile index cd030263..86ed7c26 100755 --- a/bin/compile +++ b/bin/compile @@ -2,20 +2,22 @@ set -e +BIN_DIR=$(cd $(dirname $0); pwd) # absolute path +ROOT_DIR=$(dirname $BIN_DIR) mkdir -p "$1/bin/" -cp "bin/nginx-$STACK" "$1/bin/nginx" -nginx_version=$(./bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }') +cp "${ROOT_DIR}/bin/nginx-hmrc" "$1/bin/nginx" +nginx_version=$(${ROOT_DIR}/bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }') echo "-----> nginx-buildpack: Installed ${nginx_version} to app/bin" -cp bin/start-nginx "$1/bin/" +cp ${ROOT_DIR}/bin/start-nginx "$1/bin/" echo '-----> nginx-buildpack: Added start-nginx to app/bin' mkdir -p "$1/config" -cp config/mime.types "$1/config/" +cp ${ROOT_DIR}/config/mime.types "$1/config/" echo '-----> nginx-buildpack: Default mime.types copied to app/config/' if [[ ! -f $1/config/nginx.conf.erb ]]; then - cp config/nginx.conf.erb "$1/config/" + cp ${ROOT_DIR}/config/nginx.conf.erb "$1/config/" echo '-----> nginx-buildpack: Default config copied to app/config.' else echo '-----> nginx-buildpack: Custom config found in app/config.' diff --git a/bin/nginx-hmrc b/bin/nginx-hmrc new file mode 100755 index 00000000..4911a1fc Binary files /dev/null and b/bin/nginx-hmrc differ diff --git a/bin/start-nginx b/bin/start-nginx index 804d449f..a9377337 100755 --- a/bin/start-nginx +++ b/bin/start-nginx @@ -17,15 +17,23 @@ do done #Initialize log directory. -mkdir -p logs/nginx -touch logs/nginx/access.log logs/nginx/error.log +mkdir logs +touch logs/access.log logs/error.log echo 'buildpack=nginx at=logs-initialized' -#Start log redirection. +#Start access log redirection. ( #Redirect NGINX logs to stdout. - tail -qF -n 0 logs/nginx/*.log - echo 'logs' >$psmgr + tail -qF -n 0 logs/access.log + echo 'access_logs' >$psmgr +) & + +#Start error log redirection. +( + #Redirect NGINX logs to stdout. + tail -qF -n 0 logs/error.log | \ + python -uc $'import os\nimport json\nimport sys\nfor line in sys.stdin: print(json.dumps({"app": os.getenv("APP", "unknown"), "error": line}))' + echo 'error_logs' >$psmgr ) & #Start App Server diff --git a/config/nginx.conf.erb b/config/nginx.conf.erb index 9881850c..ff36bcbb 100644 --- a/config/nginx.conf.erb +++ b/config/nginx.conf.erb @@ -16,8 +16,8 @@ http { server_tokens off; log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id'; - access_log logs/nginx/access.log l2met; - error_log logs/nginx/error.log; + access_log logs/access.log l2met; + error_log logs/error.log; include mime.types; default_type application/octet-stream; diff --git a/repository.yaml b/repository.yaml new file mode 100644 index 00000000..f7c6ae24 --- /dev/null +++ b/repository.yaml @@ -0,0 +1 @@ +repoVisibility: public_0C3F0CE3E6E6448FAD341E7BFA50FCD333E06A20CFF05FCACE61154DDBBADF71 diff --git a/scripts/build_nginx.sh b/scripts/build_nginx.sh index 05702549..9c627d7a 100755 --- a/scripts/build_nginx.sh +++ b/scripts/build_nginx.sh @@ -9,19 +9,18 @@ # Once the dyno has is 'up' you can open your browser and navigate # this dyno's directory structure to download the nginx binary. -NGINX_VERSION=${NGINX_VERSION-1.5.7} +NGINX_VERSION=${NGINX_VERSION-1.8.0} PCRE_VERSION=${PCRE_VERSION-8.21} HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.23} +OPEN_SSL_VERSION=${OPEN_SSL_VERSION-1.0.2d} nginx_tarball_url=http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz pcre_tarball_url=http://garr.dl.sourceforge.net/project/pcre/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.bz2 headers_more_nginx_module_url=https://github.com/agentzh/headers-more-nginx-module/archive/v${HEADERS_MORE_VERSION}.tar.gz +ssl_tarball_url=https://www.openssl.org/source/openssl-${OPEN_SSL_VERSION}.tar.gz -temp_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX) -echo "Serving files from /tmp on $PORT" -cd /tmp -python -m SimpleHTTPServer $PORT & +temp_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX) cd $temp_dir echo "Temp dir: $temp_dir" @@ -35,17 +34,14 @@ echo "Downloading $pcre_tarball_url" echo "Downloading $headers_more_nginx_module_url" (cd nginx-${NGINX_VERSION} && curl -L $headers_more_nginx_module_url | tar xvz ) -( - cd nginx-${NGINX_VERSION} - ./configure \ - --with-pcre=pcre-${PCRE_VERSION} \ - --prefix=/tmp/nginx \ - --add-module=/${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION} - make install -) - -while true -do - sleep 1 - echo "." -done +echo "Downloading $ssl_tarball_url" +(cd nginx-${NGINX_VERSION} && curl -L $ssl_tarball_url | tar xvz ) + +cd nginx-${NGINX_VERSION} +./configure \ + --with-pcre=pcre-${PCRE_VERSION} \ + --prefix=/tmp/nginx \ + --add-module=/${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION} \ + --with-http_ssl_module --with-openssl=./openssl-${OPEN_SSL_VERSION} +make -j1 install +