Skip to content

Commit

Permalink
refactor nginx configs, add a few default access rules, cleanup, comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dzuelke committed May 6, 2014
1 parent f94afa6 commit 26c16de
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bin/heroku-hhvm-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Options:
Recommended approach when customizing Nginx's config
in most cases, unless you need to set http or
fundamental server level options.
[default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf]
[default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf.php]
-c <nginx.conf> The path to the full configuration file that is
included after Heroku's (or your local) Nginx config
is loaded. It must contain an 'http { ... }' block
Expand Down Expand Up @@ -129,7 +129,7 @@ php_config=${php_config:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-bui
echo "Using HHVM configuration (php.ini) file '${php_config#$HEROKU_APP_DIR/}'" >&2
php_config=$(php_passthrough "$php_config")

nginx_config_include=${nginx_config_include:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf"}
nginx_config_include=${nginx_config_include:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf.php"}
echo "Using Nginx server-level configuration include '${nginx_config_include#$HEROKU_APP_DIR/}'" >&2
nginx_config_include=$(php_passthrough "$nginx_config_include")
export HEROKU_PHP_NGINX_CONFIG_INCLUDE="$nginx_config_include"
Expand Down
4 changes: 2 additions & 2 deletions bin/heroku-php-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Options:
Recommended approach when customizing Nginx's config
in most cases, unless you need to set http or
fundamental server level options.
[default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf]
[default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf.php]
-c <nginx.conf> The path to the full configuration file that is
included after Heroku's (or your local) Nginx config
is loaded. It must contain an 'http { ... }' block
Expand Down Expand Up @@ -153,7 +153,7 @@ php_config=${php_config:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-bui
echo "Using PHP configuration (php.ini) file '${php_config#$HEROKU_APP_DIR/}'" >&2
php_config=$(php_passthrough "$php_config")

nginx_config_include=${nginx_config_include:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf"}
nginx_config_include=${nginx_config_include:-"$HEROKU_APP_DIR/$COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/nginx/default_include.conf.php"}
echo "Using Nginx server-level configuration include '${nginx_config_include#$HEROKU_APP_DIR/}'" >&2
nginx_config_include=$(php_passthrough "$nginx_config_include")
export HEROKU_PHP_NGINX_CONFIG_INCLUDE="$nginx_config_include"
Expand Down
3 changes: 0 additions & 3 deletions conf/nginx/default_include.conf

This file was deleted.

8 changes: 8 additions & 0 deletions conf/nginx/default_include.conf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
location / {
index index.php index.html index.htm;
}

# for people with app root as doc root, restrict access to a few things
location ~ ^/(composer\.|Procfile$|<?=getenv('COMPOSER_VENDOR_DIR')?>/|<?=getenv('COMPOSER_BIN_DIR')?>/) {
deny all;
}
20 changes: 18 additions & 2 deletions conf/nginx/heroku.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

fastcgi_buffers 256 4k;

# define an easy to reference name that can be used in fastgi_pass
upstream heroku-fcgi {
#server 127.0.0.1:4999 max_fails=3 fail_timeout=3s;
server unix:/tmp/heroku.fcgi.<?=getenv('PORT')?:'8080'?>.sock max_fails=3 fail_timeout=3s;
Expand All @@ -34,11 +35,26 @@

include <?=getenv('HEROKU_PHP_NGINX_CONFIG_INCLUDE')?>;

# restrict access to hidden files, just in case
location ~ /\. {
deny all;
}

# default handling of .php
location ~ \.php {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# try_files resets $fastcgi_path_info, see http://trac.nginx.org/nginx/ticket/321, so we use the if instead
fastcgi_param PATH_INFO $fastcgi_path_info;

if (!-f $document_root$fastcgi_script_name) {
# check if the script exists
# otherwise, /foo.jpg/bar.php would get passed to FPM, which wouldn't run it as it's not in the list of allowed extensions, but this check is a good idea anyway, just in case
return 404;
}

fastcgi_pass heroku-fcgi;
}
}
Expand Down

0 comments on commit 26c16de

Please sign in to comment.