NGINX Unit

Ruby on Rails§

To run apps based on the Ruby on Rails framework using Unit:

  1. Install Unit with a Ruby language module.

  2. Install Ruby on Rails and create or deploy your app. Here, we use Ruby on Rails’s basic template:

    $ cd /path/to/
    
    $ rails new app
    

    This creates the app’s directory tree at /path/to/app/; its public/ subdirectory contains the static files, while the entry point is /path/to/app/config.ru.

  3. Run the following command so Unit can access the application directory:

    # chown -R unit:unit /path/to/app/
    

    Note

    The unit:unit user-group pair is available only with official packages, Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  4. Next, prepare the Ruby on Rails configuration (use real values for share and working_directory):

    {
        "listeners": {
            "*:80": {
                "pass": "routes"
            }
        },
    
        "routes": [
            {
                "action": {
                    "share": "/path/to/app/public$uri",
                    "fallback": {
                        "pass": "applications/rails"
                    }
                }
            }
        ],
    
        "applications": {
            "rails": {
                "type": "ruby",
                "script": "config.ru",
                "working_directory": "/path/to/app/"
            }
        }
    }
    
  5. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd -h or see Startup and Shutdown for details.

    After a successful update, your app should be available on the listener’s IP address and port:

    Ruby on Rails Basic Template App on Unit