tonycoco / heroku-buildpack-ember-cli

A Heroku Buildpack for Ember CLI Applications
MIT License
321 stars 121 forks source link

Using Openresty instead of Nginx #134

Closed danconnell closed 8 years ago

danconnell commented 8 years ago

This isn't a bug, I just wanted to document this here in case anyone else is curious about how to do this.

Basically, I needed to get Nginx with Lua running with this buildpack so I decided to use Openresty.

To build Openresty for Heroku:

  1. Find out what the latest versions of PCRE and Openresty are - for this documentation, it's PCRE v8.39 and Openresty v1.9.15.1
  2. Create a test Heroku machine - for this documentation, it's named openresty-test
  3. heroku run bash -a openresty-test
  4. mkdir vendor
  5. cd vendor
  6. curl -O -L http://downloads.sourceforge.net/sourceforge/pcre/pcre-8.39.tar.gz
  7. curl -O -L http://openresty.org/download/ngx_openresty-1.9.15.1.tar.gz
  8. tar xzf pcre-8.39.tar.gz
  9. tar xzf ngx_openresty-1.9.15.1.tar.gz
  10. cd openresty-1.9.15.1
  11. PATH=$PATH:/sbin ./configure --prefix=/app/vendor/openresty-heroku-build --with-pcre=/app/vendor/pcre-8.39 --with-luajit --with-http_postgres_module --with-file-aio --with-ipv6 --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-pcre-jit --with-http_iconv_module -j2
  12. make
  13. make install
  14. tar -czvf openresty-1.9.15.1-heroku-build.tar.gz openresty-heroku-build openresty-1.9.15.1
  15. Commit openresty-1.9.15.1-heroku-build.tar.gz to your fork of the heroku-ember-cli-buildpack repo
  16. Update bin/compile and bin/boot.sh in your fork of the heroku-ember-cli-buildpack repo to use the new openresty version

Changes to bin/boot.sh:

  1. Need to add in an EXPORT for Lua: export LD_LIBRARY_PATH=$HOME/vendor/openresty-1.9.15.1/build/luajit-root/app/vendor/openresty-heroku-build/luajit/lib:$LD_LIBRARY_PATH
  2. Change the path for execing nginx

Changes to bin/compile:

  1. Extract the Openresty build from the repository instead of curling the Nginx build

You can see my end result in this commit: https://github.com/danconnell/heroku-buildpack-ember-cli/commit/3ba22439e09e0f7b347b6e52f83de3f2adaaee57

You can then use Lua commands in your nginx config like so:

location ~ [A-Z] {
  rewrite_by_lua 'return ngx.redirect(string.lower(ngx.var.uri), ngx.HTTP_MOVED_PERMANENTLY)';
}
tonycoco commented 8 years ago

Whoa, very cool. Thanks for sharing!