Back

Application creation with Nginx Unit

Creating an application with Nginx Unit 

Nginx Unit is a lightweight and multifunctional application runtime that provides all the necessary tools for your website’s application in a single open-source server - it runs the application code, serves static resources, handles TLS (Transport Layer Security), and routes requests. In this tutorial, you will learn how to create a Ruby application using Nginx Unit.

You can find the Nginx Unit configuration in your E-COMMERCE or PLUS hosting plan DirectAdmin control panel here: Advanced Features > Nginx Unit

On this page, you can perform two main actions: create an application and create a route. To add a new Unit application, you first need to create a directory, place the configuration file inside it, and assign the correct user permissions.



Creating a “Hello World!” Ruby Application

In this example, we will create a simple application using the Ruby programming language that prints text on the website page.

1. Creating a New Directory

In the DirectAdmin control panel, open the command line: (System Info & Files > Terminal).

In the command line, create a new directory named “app” located in `/home/(username)/domains/(domain)/`.
User – The username for your website hosting server. You can check it using the `whoami` command. In this example, the username used is - rfcfeature.
Domain – Your website’s domain where you are creating the application. In our case, the domain used in this guide is – features.rfox.site.

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

Assign your user and group ownership to the newly created directory so that you can use it:
chown -R rfcfeature:rfcfeature /home/rfcfeature/domains/features.rfox.site/aplikacija

Enter the application directory with this command:
cd /home/rfcfeature/domains/features.rfox.site/aplikacija

Create the Ruby configuration file for the Nginx Unit application:
nano config.ru

In the opened “Nano” text editor, paste the following sample configuration:
app = Proc.new do |env|
    ["200", {
        "Content-Type" => "text/plain",
    }, ["Hello, Ruby on Unit!"]]
end
run app

Save the changes by pressing `CTRL + X`, then `Y`, and finally `Enter`.

Assign execution permissions to the created file:
chmod +x config.ru

2. Creating the Nginx Unit Application

After preparing the directory and configuration file, go to the DirectAdmin control panel, open the page Advanced Features > Nginx Unit, and add a new application:

Name - Specify the name of the application, which must match the directory name (e.g., “app”).

Type - Select the programming language you are using (e.g., Ruby).

Working directory - Provide the path to the application’s configuration file. In our case, the directory path is - /home/rfcfeature/domains/features.rfox.site/aplikacija/config.ru.


After filling out all the information, click the “Create” button.

3. Route Configuration

In the Nginx Unit page, next to the newly created application, click “Create Route”.


Most of the route configuration fields will be filled in automatically. Click “Create” to save the route.

Testing the Application

After completing all the above steps, check your newly created application by entering your domain in a browser. If everything was done correctly, you will see a message like this:


Therefore, to create an Nginx Unit application, you must create a configuration file and add a new application and route in the DirectAdmin control panel. If you encounter any issues, please contact us via live support or by email at: [email protected]

Similar tutorials

Static vs Dynamic Websites: What’s the Difference and Which One Should You Choose? Hello!Ever wondered what makes one website load at lightning speed and another feel...

Read

HTTPS protocol - currently seems mandatory for everyone on the web. Getting an SSL certificate is now easier than ever. Let’s encrypt allows you to...

Read
Shared Hosting Tutorials
For a consultation, please contact us by email:
[email protected]