Enable Phusion Passenger on Nginx

Follow these steps:

  • Stop the NGINX service:

    $ /opt/bitnami/ stop nginx
  • Modify the server configuration in the /opt/bitnami/nginx/conf/nginx.conf file so that it looks similar to this:

    server {
        listen 80;
        root /opt/bitnami/apps;
        passenger_enabled on;
        pagespeed on;
        pagespeed FileCachePath /opt/bitnami/nginx/var/ngx_pagespeed_cache;
        #  Ensure requests for pagespeed optimized resources go to the pagespeed
        #  handler and no extraneous headers get set.
        location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
        location ~ "^/ngx_pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }
        location /ngx_pagespeed_statistics { allow; deny all; }
        location /ngx_pagespeed_message { allow; deny all; }

    With this code, you will be running your Ruby on Rails application at the root of your domain, and will be running through the default HTTP port (80). Before restarting NGINX to apply this configuration, we recommend disabling Apache from starting by default.

    To do this, run these commands:

    $ /opt/bitnami/ stop apache
    $ mv /opt/bitnami/apache2/scripts/ /opt/bitnami/apache2/scripts/
    $ mv /opt/bitnami/config/monit/conf.d/apache.conf /opt/bitnami/config/monit/apache.conf.disabled
  • Restart the NGINX service to apply the new configuration:

    $ /opt/bitnami/ restart nginx

Access your Ruby on Rails applications with NGINX and Passenger at http://SERVER-IP/.

Last modification September 9, 2018