Back Back

How to Create an Application with Nginx Unit

Nginx Unit lets you run a Ruby, Python, PHP, Node.js or Go application on your hosting without renting a separate server. In this tutorial, you’ll create a simple Ruby application that prints text on your website.

What you need before you start

  • A web hosting E-COMMERCE or PLUS plan. Nginx Unit is only available on these plans.
  • The domain the application will run on.
  • Access to the DirectAdmin control panel.

Creating the application

  1. Open the terminal

    In DirectAdmin, go to System Info & Files > Terminal.

    The terminal in the DirectAdmin control panel.

    First, find your username on the server. You’ll need it in every path:

    whoami
    The command shows your username.

    This tutorial uses the user rfcfeature and the domain features.rfox.site. Replace them with your own in the commands.

  2. Create the application directory

    Create a new directory inside your domain folder:

    mkdir /home/rfcfeature/domains/features.rfox.site/aplikacija

    Open it:

    cd /home/rfcfeature/domains/features.rfox.site/aplikacija
    No permission changes needed

    The directory already belongs to your user, so you don’t need to set any extra permissions.

  3. Create the config.ru file

    Create the configuration file for the Nginx Unit application:

    nano config.ru

    In the Nano editor that opens, paste this example code:

    app = Proc.new do |env| ["200", { "Content-Type" => "text/plain", }, ["Hello, Ruby on Unit!"]] end run app
    How to save

    Ctrl + O and Enter saves the file, Ctrl + X exits the editor.

  4. Create the application in DirectAdmin

    Go to Advanced Features > Nginx Unit. Applications and routes are created on this page.

    The Nginx Unit management page.

    Click the add application button and fill in the fields:

    Creating a new Nginx Unit application.
    • Name – the application name, the same as the directory, e.g. aplikacija.
    • Type – the programming language, in this case Ruby.
    • Working directory – the full path to the config.ru file:
    /home/rfcfeature/domains/features.rfox.site/aplikacija/config.ru
    The completed application details.

    Click Create.

  5. Create a route

    Next to the newly created application, click Create Route.

    Creating a route for the application.

    Most fields are filled in automatically. Click Create.

    The route settings are filled in automatically.

Did it work?

Open your domain in a browser. You should see the text printed by the application:

The application is running.

FAQ

I see an error or the old website in the browser

Check that the route was created and that the Working directory field contains the full path to the config.ru file, not just the directory.

How do I find my username and domain path?

Enter whoami in the terminal. Domain directories are under /home/username/domains/.

Can I use another programming language?

Yes. The Type field offers Python, PHP, Node.js, Go, Perl and Java. Only the entry file differs, e.g. wsgi.py for Python or app.js for Node.js.

How do I remove an application?

On the Nginx Unit page, delete the route first, then the application itself. You can delete the directory with the files in the file manager or the terminal.

What’s next

If you run into trouble, contact us via live chat or email.

Similar tutorials

Shared Hosting Tutorials