virtualMachineruby

Enable Phusion Passenger on Nginx

Follow these steps:

  • Stop the NGINX service:

    $ /opt/bitnami/ctlscript.sh 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;
        server_name example.com;
        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 127.0.0.1; deny all; }
        location /ngx_pagespeed_message { allow 127.0.0.1; 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/ctlscript.sh stop apache
    $ mv /opt/bitnami/apache2/scripts/ctl.sh /opt/bitnami/apache2/scripts/ctl.sh.disabled
    $ 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/ctlscript.sh restart nginx
    

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