Setting up Phusion Passenger with Apache 2.4 on Ubuntu

Phusion Passenger

Install Apache 2

1
2
3
sudo apt-get install apache2
sudo a2enmod headers
sudo a2enmod expires

Configure Apache SSL

1
2
3
4
sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo mkdir /etc/apache2/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Install Phusion Passenger

1
2
gem install passenger
passenger-install-apache2-module

Follow on screen instructions, so the apache configuration file /etc/apache2/apache2.conf looks like:

1
2
3
4
5
LoadModule passenger_module /home/yuxi/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/passenger-5.1.5/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/yuxi/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/passenger-5.1.5
PassengerDefaultRuby /home/yuxi/.rbenv/versions/2.3.1/bin/ruby
</IfModule>

Configure Rails application in Apache 2.x

Edit /etc/apache2/sites-enabled/default-ssl.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin [email protected]
ServerName localhost
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
RailsEnv production
RailsBaseURI /
Alias / /home/yuxi/rails_app/public
<Location />
PassengerBaseURI /
PassengerAppRoot /home/yuxi/rails_app
</Location>
<Directory /home/yuxi/rails_app/public>
Require all granted
AllowOverride None
Options -MultiViews +FollowSymLinks
Require all granted
</Directory>
<Location /assets/>
Require all granted
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</Location>
</VirtualHost>
</IfModule>

Configurations within Rails application

Generate assets for production:

1
rake assets:precompile RAILS_ENV=production

Edit config/environments/production.rb, make sure:

1
config.public_file_server.enabled = true
Share