diff --git a/README.md b/README.md index dd226ac..1f5b03a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ This buildpack has been successfully run on Digital Ocean instances of Ubuntu 14 All static files that you want to serve should be in the root directory of your repository. No need to use a seperate `www` folder. `buildpack-nginx` will automatically download the buildpack, download NGINX, compile it, and install it. The next time you push your project, the buildpack will reuse the precompiled binaries. +## NGINX CONFIGURATION +Override default configuration by adding `nginx.conf.erb` in the root directory + ## Credits and License `buildpack-nginx` is licensed under the CC0 1.0 Universal license and has been informed by many similar projects on the web diff --git a/bin/compile b/bin/compile index e58a421..f003c9f 100755 --- a/bin/compile +++ b/bin/compile @@ -26,6 +26,8 @@ if [[ ! -e "$BUILD_DIR/www" ]]; then mv $BUILD_DIR/* $CACHE_DIR/www mkdir -p $BUILD_DIR/www mv $CACHE_DIR/www/* $BUILD_DIR/www + # Check for an copy the nginx conf file override to the build dir + [[ -f "$BUILD_DIR/www/nginx.conf.erb" ]] && mv $BUILD_DIR/www/nginx.conf.erb $BUILD_DIR [[ -f "$BUILD_DIR/www/CHECKS" ]] && mv $BUILD_DIR/www/CHECKS $BUILD_DIR rm -rf $CACHE_DIR/www fi @@ -114,11 +116,18 @@ EOF cd $CUR_DIR -# build nginx config unless overridden by user -#if [ ! -f $BUILD_DIR/nginx/nginx.conf ] ; then -echo "-----> using default nginx.conf.erb" -cp conf/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb -#fi + +# Test for user override on nginx config... +if [ -f $BUILD_DIR/nginx.conf.erb ] ; then + echo "-----> using user provided nginx.conf.erb" + cp $BUILD_DIR/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb + #rm $BUILD_DIR/nginx.conf.erb + +# ...else, force default file +else + echo "-----> using default nginx.conf.erb" + cp conf/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb +fi # build mime.types unless overridden by user #if [ ! -f $BUILD_DIR/mime.types ] ; then @@ -131,6 +140,6 @@ cat <"$BUILD_DIR/start_nginx" #!/usr/bin/env bash rm -f /app/nginx/nginx.conf erb /app/nginx/nginx.conf.erb > /app/nginx/nginx.conf -exec nginx -p /app/nginx -c /app/nginx/nginx.conf +exec /app/nginx/nginx -p /app/nginx -c /app/nginx/nginx.conf EOF chmod +x "$BUILD_DIR/start_nginx" diff --git a/conf/nginx.conf.erb b/conf/nginx.conf.erb index 2189ddb..82e8b4d 100644 --- a/conf/nginx.conf.erb +++ b/conf/nginx.conf.erb @@ -13,7 +13,11 @@ http { server { listen <%= ENV["PORT"] %>; server_name _; - root /app/www; + <% if ENV["ROOT"] %> + root /app/www/<%= ENV["ROOT"] %>; + <% else %> + root /app/www; + <% end %> index index.html; } }