Nginx Unit Deep Dive: Install, Configure PHP, and Benchmark vs tengine+php-fpm

This article introduces Nginx Unit, walks through its installation on CentOS 6.9, shows how to configure a simple PHP application using JSON, and presents a performance comparison with tengine + php‑fpm, demonstrating significantly higher QPS and lower request latency for Unit.

Beike Product & Technology
Beike Product & Technology
Beike Product & Technology
Nginx Unit Deep Dive: Install, Configure PHP, and Benchmark vs tengine+php-fpm

1. Nginx Unit Overview

Nginx Unit is an open‑source, Nginx‑based web server that supports multiple languages such as Python, PHP, and Go. It enables dynamic reconfiguration via a RESTful JSON API without restarting the service, using isolated router processes to manage incoming HTTP requests and application process groups.

Dynamic reconfiguration with RESTful JSON API

Supports multiple languages and multiple versions simultaneously

Upcoming features include dynamic language process management, TLS support, and routing/proxy for TCP, HTTP, HTTPS, and HTTP/2.

2. Installation

Example for CentOS 6.9:

Create the repository file /etc/yum.repos.d/unit.repo with the following content:

1 [unit]
2 name=unit repo
3 baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
4 gpgcheck=0
5 enabled=1

Install the package:

# yum install unit

3. Configuration and Run

Each application is defined in a JSON configuration file. The example below creates an application named php-test located at /data0/www/htdocs/nginxUnit/.

Create the working directory and an index.php test file:

# cd /data0/www/htdocs/nginxUnit/
<?php
echo "hello world";
?>

Create phpConfig.json with the following content:

{
  "listeners": {
    "*:8100": { "application": "php-test" }
  },
  "applications": {
    "php-test": {
      "type": "php",
      "processes": 20,
      "root": "/data0/www/htdocs/nginxUnit",
      "index": "index.php"
    }
  }
}

Apply the configuration via the control socket:

# curl -X PUT -d @/data0/www/htdocs/phpConfig.json --unix-socket /var/run/control.unit.sock http://localhost

On success the server returns: { "success": "Reconfiguration done." } Visit http://localhost:8100/ to verify that index.php runs correctly. The environment setup and application configuration are now complete.

4. Performance Comparison

The article compares Nginx Unit with the existing tengine + php‑fpm stack.

Test environment:

Configuration snippets:

{
  "listeners": { "*:8100": { "application": "php-test" } },
  "applications": { "php-test": { "type": "php", "processes": 20, "root": "/data0/www/htdocs/nginxUnit", "index": "index.php" } }
}
[unit.local]
user = www
group = www
listen = 127.0.0.1:9008
listen.allowed_clients = 127.0.0.1
pm = static
pm.max_children = 20
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 32
pm.max_requests = 1500
pm.status_path = /h3_monitor
slowlog = /data0/www/logs/$pool-slow_log
request_slowlog_timeout = 3
request_terminate_timeout = 20
catch_workers_output = no
security.limit_extensions = ""

Load‑testing commands (ApacheBench, 10 runs each, average QPS taken):

ab -n 10000 -c 100 http://127.0.0.1:8100/
ab -n 10000 -c 100 http://unit.local/
ab -n 10000 -c 50 http://unit.local/
ab -n 10000 -c 50 http://127.0.0.1:8100/
ab -n 1000 -c 50 http://127.0.0.1:8100/
ab -n 1000 -c 50 http://unit.local/

Result chart:

Performance comparison chart
Performance comparison chart

Interpretation of the three rows of data:

With the same concurrency (50), increasing total requests from 1 000 to 10 000 raises QPS and reduces average request time for both stacks.

When comparing tengine + php‑fpm to Nginx + Unit at 50 concurrency and 10 000 total requests, Nginx + Unit achieves 91 % higher QPS and 87.5 % lower average request time.

Conclusion: Nginx + Unit delivers noticeably higher QPS and lower latency for plain‑text responses than the tengine + php‑fpm combination, and its dynamic configuration model offers strong future flexibility.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendperformanceConfigurationPHPNGINXWeb serverunit
Beike Product & Technology
Written by

Beike Product & Technology

As Beike's official product and technology account, we are committed to building a platform for sharing Beike's product and technology insights, targeting internet/O2O developers and product professionals. We share high-quality original articles, tech salon events, and recruitment information weekly. Welcome to follow us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.