BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News NGINX Releases Open Source Web Server with Dynamic Configuration

NGINX Releases Open Source Web Server with Dynamic Configuration

This item in japanese

Bookmarks

NGINX recently released version 1.0 of Unit, an open-source web and application server. The server supports remote and dynamic configuration and incurs no service interruptions for configuration changes. Unit 1.0 also supports multiple languages (Go, Perl, PHP, Python, and Ruby) running on the same instance, including multiple versions of the same language.

NGINX Unit does not rely on a static configuration file, but is instead configured via a REST API using JSON. All configuration is stored directly in memory, allowing for changes to happen without restarting the running services. The router process is persistent and does not require a restart.

The basic configuration requires at least one listener and one application. The listener details on which port and IP address Unit will listen to and redirect to a named application. An application definition allows for specification of the language, the directories for the application's files, and the number of processes.

For example, you can define a listener on port 8300 to serve a PHP application located in /www/blogs/scripts using up to 20 processes:

{
    "listeners": {
        "*:8300": {
            "application": "blogs"
        }
    },

    "applications": {
        "blogs": {
            "type": "php",
            "processes": 20,
            "root": "/www/blogs/scripts",
            "index": "index.php"
        }
    }
}

The recommendation from Unit's documentation is to store this in a (version controlled) file and then post it to the server. If the data above is stored in a file called start.json, an initial configuration can be created as follows:

# curl -X PUT -d @/path/to/start.json --unix-socket /path/to/control.unit.sock http://localhost/

Unit keeps the router process separate from the application processes, which run the application code. Each application process pool is run in its own sandbox to ensure isolation from other processes. This isolation permits multiple applications running in different languages to share the same server.

NGINX Unit architecture (credit: NGINX)

NGINX Unit architecture (credit: NGINX)

 

In the following example, a Go and a Perl application are setup to run on the same Unit server:

{
    "listeners": {
       "*:8500": {
            "application": "go_chat_app"
        },

        "127.0.0.1:8600": {
            "application": "bugtracker"
        }
    },

    "applications": {
        "go_chat_app": {
            "type": "go",
            "user": "www-chat",
            "group": "www-chat",
            "working_directory": "/www/chat",
            "executable": "bin/chat_app"
        },
        "bugtracker": {
            "type": "perl",
            "processes": 3,
            "user": "www",
            "group": "www",
            "working_directory": "/www/bugtracker",
            "script": "app.psgi"
        }    }
}

According to Owen Garrett, head of products at NGINX, Unit is suitable for stand-alone or microservices-based architectures. It supports on-demand scaling of processes, executing each process in its own sandbox.

NGINX plans to add language support for Java and Node.js in an upcoming release. The company has plans to support SSL and HTTP/2 as well as support for serving static content and routing using URIs and hostnames.

NGINX Unit is open source (Apache License 2.0) and there are pre-built packages available for most operating systems, including Debian, CentOS, Ubuntu, and others. There is also a Docker container available on Docker Hub.

Rate this Article

Adoption
Style

BT