on March 5, 2017 by Kurt Tomlinson
Making OpenResty and Passenger work together isn't too hard, but it's not obvious how to do it. There's a lot of guides for getting Passenger to work with Nginx, but the process for OpenResty is a little different. For that reason, I'm documenting how I got them to work together here.
The script below installs RVM and version 2.3.3 of Ruby. To check for newer versions of Ruby you can ask RVM to list all known rubies with rvm list known.
echo "INSTALL RUBY WITH RVM"
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
rvm use 2.3.3 --install --default
If we're going to use a Ruby gem, we might as well update the platform.
echo "UPDATE RUBYGEMS"
gem install rubygems-update --no-rdoc --no-ri
gem update --system
gem pristine --all
The Passenger gem is an easy way to get the passenger source code onto your system. We need it so we can compile passenger into OpenResty.
echo "INSTALL PASSENGER GEM"
gem install passenger --version 5.1.2 --no-rdoc --no-ri
You can check for the latest version on the Passenger RubyGems page.
In this step, we do several things. First we download the OpenResty source code. (Check the OpenResty download page for the latest version of OpenResty.) Then we unpack it. Then we configure it and indicate that we want to add the passenger module. Finally, we make and install it into /opt/openresty/. The configure options are the same options that the Passenger gem uses when installing Passenger+Nginx with the command passenger-install-nginx-module. (You can't use passenger-install-nginx-module with OpenResty because OpenResty's configure script is a Perl script, and passenger-install-nginx-module tries to call it with sh. Trying to run a Perl script as a Bash script results in all kinds of bad things.)
echo "INSTALL OPENRESTY (NGINX) AND PASSENGER"
tar xvfz openresty-188.8.131.52.tar.gz
./configure --prefix='/opt/openresty' \
sudo make install
If you follow the directions above, you will have Ruby 2.3.3, OpenResty 184.108.40.206, and Passenger 5.1.2 installed on your system. Ruby will be installed at ~/.rvm/rubies/ruby-2.3.3/bin/ruby OpenResty will be installed at /opt/openresty. And Passenger will be installed at ~/.rvm/gems/ruby-2.3.3/gems/passenger-5.1.2