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.

    Quick reference card

      Cloud Servers Virtual Machines Native Installers
    Configuration file(s) /opt/bitnami/nginx/conf/nginx.conf /opt/bitnami/nginx/conf/nginx.conf install_dir/nginx/conf/nginx.conf
    Log file(s) /opt/bitnami/nginx/logs/* /opt/bitnami/nginx/logs/* install_dir/nginx/logs/*
    Default port 1234 (Ruby Stack) or 80 otherwise 1234 (Ruby Stack) or 80 otherwise 1234 (Ruby Stack) or 80 otherwise
    System user account daemon daemon daemon
    Service control sudo /opt/bitnami/ start|stop|restart nginx sudo /opt/bitnami/ start|stop|restart nginx install_dir/ start|stop|restart nginx

    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 "" script:

    $ cd installdir
    $ mv nginx/scripts/ nginx/scripts/

    By default, Nginx will be started at the 1234 port. Check http://localhost:1234 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 have 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 on port 80, you must stop the apache service before. To do it, you must run:

    /opt/bitnami/ 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;
        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 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 disabling apache from the RubyStack default services.

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

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

    /opt/bitnami/ restart nginx

    And with the last step, you will be able to access to your Ruby on Rails applications with Nginx + Passenger on 

    How to enable Pagespeed?

    Nginx server is configured by default to use the PageSpeed module.

    To configure Pagespeed with Nginx, you should a few lines inside the 'server' directive in the Bitnami Nginx configuration file located at "/installdir/nginx/conf/bitnami/bitnami.conf". Just like the following snippet.

       server {
        listen 80;
        location /status {
          stub_status on;
          access_log   off;
          deny all;
        pagespeed on;
        # needs to exist and be writable by nginx
        pagespeed FileCachePath /installdir/nginx/var/ngx_pagespeed_cache;
        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; }
      include "/installdir/nginx/conf/vhosts/*.conf";
    Then restart the server or reload its configuration
    # Restart the server
    $ sudo /installdir/ restart nginx
    # Or reload its configuration
    $ sudo nginx -s reload
    To confirm that the module is loaded, fetch a page and check that you see the X-Page-Speed header:
    $ curl -I '' | grep X-Page-Speed

    Tag page (Edit tags)
    • No tags
    Page statistics
    35987 view(s), 12 edit(s) and 5701 character(s)


    You must login to post a comment.

    Attach file