Heroku Nginx configuration

The Setup
A PHP application with NGINX web server runs on Heroku infrastructure.
It is quite easy to add application level Nginx configuration rules. Follow theirs documentation Custom PHP settings. It gets complicated if you want to edit something in Nginx `http` configuration block (server level configuration).
I wanted to use `ngx_http_limit_req_module`. This requires adding `limit_req_zone` in http block. So, I can not add it into configuration file from the above tutorial.
Virtually, you need to and one line into `conf/nginx/heroku.conf.php` of Heroku PHP builpack
First approach
Why not clone Heroku PHP buildpack official repo, edit that file. Then change application buildpack and ready to go! It was pretty easy and straight forward change.
Apparently, buildpacks tend to change. After a month of using custom buildpack, every application build process failed. Forked buildpack repo sync with the origin fixed the issue. This accident rang a bell to find a better solution for this. Heroku support gave one.
I would say it is typical “wanted a banana, got a gorilla holding a banana in the jungle” example.
Second approach
Heroku support suggested using -c option in Procfile to override server-level configuration file. The same file I edited previous in the forked repo. So:
- created new file in the project,
- copied contents from official conf/nginx/heroku.conf.php file,
- added custom modifications (limit_req_zone) rules,
- edited Procfile to use both
-cand-Coptions (server and application configuration files), - set application buildpack to default one — `heroku/php`.
Currently, only one file is overridden instead of the whole repo. This will lead to less failed builds when builpack repo changes.
