What Is Nginx Unit?
Nginx Unit is a dynamic application server that supports multiple languages including PHP, Python, Go, and Node.js. It uses a RESTful JSON API for configuration, allowing you to update settings and deploy applications on your Breeze without restarts or downtime.
Prerequisites
- A Breeze running Ubuntu 22.04 or later
- Root or sudo access
Step 1: Install Nginx Unit
curl --output /usr/share/keyrings/nginx-keyring.gpg https://unit.nginx.org/keys/nginx-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/ubuntu/ $(lsb_release -cs) unit" | sudo tee /etc/apt/sources.list.d/unit.list
sudo apt update
sudo apt install unit unit-php unit-python3.11Step 2: Start the Service
sudo systemctl enable unit
sudo systemctl start unitStep 3: Deploy a PHP Application
Create a JSON configuration file:
sudo nano /tmp/app-config.json{
"listeners": {
"*:8080": {
"pass": "applications/myapp"
}
},
"applications": {
"myapp": {
"type": "php",
"root": "/var/www/myapp/public",
"index": "index.php"
}
}
}Step 4: Apply the Configuration
sudo curl -X PUT --data-binary @/tmp/app-config.json \
--unix-socket /var/run/control.unit.sock \
http://localhost/configStep 5: Verify the Deployment
curl http://localhost:8080Check the current running configuration at any time:
sudo curl --unix-socket /var/run/control.unit.sock http://localhost/configKey Advantages
- Zero-downtime configuration changes via the API
- Run multiple language runtimes side by side on one Breeze
- Lightweight process model with low memory overhead
- Pair with Nginx as a reverse proxy for SSL termination in production