docker.recipes

NGINX Unit

intermediate

Dynamic application server supporting multiple languages.

Overview

NGINX Unit is a dynamic application server developed by NGINX Inc. that revolutionizes web application deployment by supporting multiple programming languages within a single server process. Unlike traditional web servers that require separate processes or modules for different languages, Unit can natively execute PHP, Python, Go, Ruby, Node.js, Java, and Perl applications through its polyglot architecture. This eliminates the complexity of managing multiple application servers and reduces resource overhead significantly. NGINX Unit's standout capability is its dynamic reconfiguration system that operates through a REST API, allowing administrators to modify application configurations, routing rules, and server settings without requiring restarts or service interruptions. The server maintains application state during configuration changes, enabling true zero-downtime deployments. This makes Unit particularly valuable for organizations running mixed-language environments or requiring frequent deployment cycles without service disruption. This setup is ideal for development teams working with microservices in different languages, hosting providers managing multi-tenant applications, and organizations seeking to consolidate their application server infrastructure. Unit's ability to handle multiple applications simultaneously while providing isolated execution environments makes it perfect for reducing operational complexity while maintaining performance and security boundaries between applications.

Key Features

  • Native multi-language support for PHP, Python, Go, Ruby, Node.js, Java, and Perl in a single server process
  • Dynamic reconfiguration via REST API without service restarts or downtime
  • Zero-downtime application deployments with graceful configuration transitions
  • Per-application isolation with independent memory spaces and resource limits
  • Advanced request routing with pattern matching, load balancing, and traffic splitting
  • Real-time statistics and monitoring through the control API endpoint
  • Automatic process management with configurable limits and scaling policies
  • Built-in support for WebSocket connections across all supported languages

Common Use Cases

  • 1Multi-language microservices architecture requiring a unified application server
  • 2Development environments needing to test applications in different programming languages
  • 3Continuous integration pipelines requiring zero-downtime deployments
  • 4Hosting platforms serving multiple customer applications with different language requirements
  • 5A/B testing environments with traffic splitting between application versions
  • 6Legacy application modernization where different components use different languages
  • 7Educational platforms demonstrating web applications across multiple programming languages

Prerequisites

  • Minimum 512MB RAM recommended for running multiple language runtimes
  • Docker and Docker Compose installed on the host system
  • Port 80 and 8080 available on the host machine
  • Basic understanding of JSON configuration format for Unit setup
  • Familiarity with REST API concepts for dynamic configuration management
  • Application code prepared in supported languages (PHP, Python, Go, Ruby, Node.js, Java, Perl)

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 unit:
3 image: unit:latest
4 container_name: nginx-unit
5 restart: unless-stopped
6 volumes:
7 - ./app:/www
8 - ./unit/config.json:/docker-entrypoint.d/config.json:ro
9 ports:
10 - "80:80"
11 - "8080:8080"
12 networks:
13 - unit-network
14
15networks:
16 unit-network:
17 driver: bridge

.env Template

.env
1# NGINX Unit configuration via JSON

Usage Notes

  1. 1Docs: https://unit.nginx.org/
  2. 2Polyglot server: PHP, Python, Go, Ruby, Node.js, Java, Perl
  3. 3Dynamic reconfiguration via REST API - no restarts needed
  4. 4Control API: curl --unix-socket /var/run/control.unit.sock http://localhost/
  5. 5Zero downtime deployments - change config on the fly
  6. 6Configure via JSON - applications, routes, listeners

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 unit:
5 image: unit:latest
6 container_name: nginx-unit
7 restart: unless-stopped
8 volumes:
9 - ./app:/www
10 - ./unit/config.json:/docker-entrypoint.d/config.json:ro
11 ports:
12 - "80:80"
13 - "8080:8080"
14 networks:
15 - unit-network
16
17networks:
18 unit-network:
19 driver: bridge
20EOF
21
22# 2. Create the .env file
23cat > .env << 'EOF'
24# NGINX Unit configuration via JSON
25EOF
26
27# 3. Start the services
28docker compose up -d
29
30# 4. View logs
31docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/unit/run | bash

Troubleshooting

  • Unit control socket permission denied: Ensure the container has proper permissions to access /var/run/control.unit.sock
  • Application fails to start with 'module not found': Verify the application path is correctly mounted and accessible within the container
  • Configuration API returns 400 Bad Request: Validate JSON configuration syntax using a JSON validator before applying
  • Multiple language applications conflict: Check that each application has unique listeners and properly isolated working directories
  • Memory exhaustion with multiple apps: Adjust per-application process limits in Unit configuration and increase container memory limits
  • Port binding fails on startup: Verify ports 80 and 8080 are not in use by other services on the host system

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space