NGinx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Currently Ruby Stack includes this server already configured.

    How to start the Nginx server?

    You can find the Nginx server in your installation directory. If you are using the Virtual Machine or the Cloud Image check the /opt/bitnami folder.

    This server is disabled by default. If you want to start it, you can simply rename the "ctl.sh.disabled" script:

    $ cd installdir
    $ mv nginx/scripts/ctl.sh.disabled nginx/scripts/ctl.sh

    By default, Nginx will be started at the 1234 port. Check http://localhost:4321 in your browser to see the Nginx welcome page.

    How to configure Nginx?

    The default configuration file for Nginx is the installdir/nginx/conf/nginx.conf file. You can change the port in the "listen" option:

    listen 1234;

    Nginx was compiled to include most popular extensions: compression options, Passenger module for Ruby applications and PageSpeed module.

    How to debug errors?

    Check the exact error in the Nginx log file: "installdir/nginx/log/error.log". If you have configured Nginx to use a privileged port (< 1024) check that the Nginx user is "daemon" in the configuration file. This user should also has write privileges in the log folder.

    How to configure Nginx + Passenger to run Ruby on Rails applications?

    This guide will work for our Cloud Instances, Bitnami Cloud Hosting and Virtual Machines. If you have installed RubyStack in your system, you must override "/opt/bitnami" with your installation directory.

    To configure Nginx to run at port 80, you must stop the apache service before. To do it, you must run:

    /opt/bitnami/ctlscript.sh stop apache

    Once the apache service has been stopped, you must modify the server configuration of /opt/bitnami/nginx/conf/nginx.conf  and be sure that your configuration is similar to this:

    server {
        listen 80;
        server_name example.com;
        root /opt/bitnami/apps7;
        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 that code, you will be running your Ruby on Rails application on the root of your domain, and will be running through the default HTTP port (80). Before restart Nginx to apply this configuration, we recommend to disable apache from the RubyStack default services.

    To do it, you only need to run this 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
    

    Now, you must restart the Nginx service to apply the new configuration

    /opt/bitnami/ctlscript.sh restart nginx

    And with the last step, you will be able to access to your Ruby on Rails applications with Nginx + Passenger on http://example.com/ 

    Tag page (Edit tags)
    • No tags
    Page statistics
    10756 view(s), 5 edit(s) and 3952 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments