NGINX Unit

Catalyst Apps§

Unit allows to run Perl web apps based on Catalyst 5.9 and later almost seamlessly:

  1. Install Unit with the appropriate Perl language module version.

  2. If you haven’t already done so, create a Catalyst app in your usual location:

    $ cd /path/to/apps/
    $ catalyst.pl myapp
    $ cd myapp && perl Makefile.PL
    $ chown -R catalyst_user:catalyst_group .
    

    Note

    Make sure the app’s .psgi file includes the lib/ directory:

    use lib 'lib';
    use myapp;
    
  3. Prepare Unit configuration for your update. To obtain an initial template, query the control API:

    # curl --unix-socket /path/to/control.unit.sock \
           http://localhost/config/ > config.json
    

    Note

    Control socket path may vary; run unitd --help or see Startup for details.

    This creates a JSON file with Unit’s current settings. Edit the file, adding a listener entry to point to a Unit app with your .psgi file; the app will run on the listener’s IP and port:

    {
        "listeners": {
            "127.0.0.1:3000": {
                "pass": "applications/catalyst_app"
            }
        },
    
        "applications": {
            "catalyst_app": {
                "type": "perl",
                "script": "/path/to/apps/myapp/myapp.psgi",
                "user": "catalyst_user",
                "group": "catalyst_group"
            }
        }
    }
    
  4. Upload the updated configuration:

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

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

    $ curl 127.0.0.1:3000