Recently I found that passenger in the last version now uses nginx 1.10.x by default, as you knows since nginx 1.9.x nginx enables support for http2 but the 1.9.x on nginx is beta and when released the line 1.10 is production ready. The process will be describe for ubuntu 14.4 and 16.4:
Install Dependencies
apt-get update -y
apt-get upgrade -y
apt-get install sudo -y
install the required packages:
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs git-core
Install Ruby
For production sites is a MUST install from sources without using any versions managers like RVM, RENV or whatever this is why leads to hard to diagnose problems. Remove the old Ruby 1.8 if present:
sudo apt-get remove ruby1.8
Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --disable-install-rdoc
make
sudo make install
Install the passenger Gem:
sudo gem install passenger --no-ri --no-rdoc
Now we need to install nginx manually, enable http2 and add the dependency to passenger:
mkdir /tmp/nginx && cd /tmp/nginx
curl -O --progress https://nginx.org/download/nginx-1.10.1.tar.gz
tar xzf nginx-1.10.1.tar.gz
cd nginx-1.10.1
# this contains all defaults options using the command passenger-install-nginx-module and http2 support
./configure --prefix='/opt/nginx' \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-cc-opt=-Wno-error \
--with-ld-opt='' \
--add-module=$(passenger-config --nginx-addon-dir) \
--with-http_v2_module
make
sudo make install
and thats it! you now have nginx + passenger + http2
Enable http2 on vhost
server {
listen 443 ssl http2;
server_name somedomain.com;
ssl_certificate path_to_your.crt;
ssl_certificate_key path_to_your.key;
root /path/to/your/rails/public;
passenger_enabled on;
passenger_set_header HTTP_X_FORWARDED_PROTO https;
}
Init script
Due to install from source this method doesn’t install as a OS service, to put a correct init I suggest to use this awesome init.d.