Configure Nginx Unit to Run Multiple Languages PHP, Python, Node.js Simultaneously on a Resource-Efficient VPS
Guide to configure Nginx Unit for running PHP, Python, and Node.js applications simultaneously on a single VPS with high performance and low resource usage. Ideal for AI, API...
Image credit: hpgruesen · Pixabay Content License
Configure Nginx Unit to Run Multiple Languages Simultaneously on a VPS
In an era of growing demand for AI, API Gateway, and self-hosted LLM applications, optimizing system resources is essential. Nginx Unit offers a powerful, lightweight solution that supports multiple programming languages such as PHP, Python, and Node.js on the same server. With high performance and low resource consumption, Nginx Unit is ideal for resource-efficient VPS environments.
Introduction to Nginx Unit
Nginx Unit is a modern application manager that supports multiple languages including PHP, Python, Node.js, Go, and Java. Unlike traditional Nginx, which acts as a reverse proxy, Unit functions as an integrated application server, allowing backend applications to run directly without needing Nginx or Apache as intermediaries. This reduces latency, boosts performance, and conserves system resources.
Requirements and Preparation
To deploy Nginx Unit on a VPS, you need:
- A Linux-based VPS (Ubuntu 20.04+ or CentOS 7+)
- Root or sudo user privileges
- Stable internet connection
- Access to official package repositories
Configuration Steps
We will install Nginx Unit and configure it to run PHP, Python, and Node.js applications simultaneously.
1. Install Nginx Unit
Add the official Nginx Unit repository and install:
wget -O - https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
echo "deb https://packages.nginx.org/unit/debian/ $(lsb_release -cs) unit" | sudo tee /etc/apt/sources.list.d/unit.list
sudo apt update
sudo apt install unit
2. Configure PHP Application
Create a simple PHP app:
<?php
echo "Hello from PHP on Nginx Unit!";
?>
Save as index.php in /var/www/php.
Create a JSON configuration for PHP:
{
"listeners": {
"127.0.0.1:8080": {
"pass": "applications/php"
}
},
"applications": {
"php": {
"type": "php",
"processes": 2,
"root": "/var/www/php",
"script": "index.php"
}
}
}
3. Configure Python Application
Create a Python app (app.py):
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello from Python on Nginx Unit!"
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8081)
Create a JSON configuration:
{
"applications": {
"python": {
"type": "python",
"processes": 2,
"working_directory": "/var/www/python",
"module": "app"
}
},
"listeners": {
"127.0.0.1:8081": {
"pass": "applications/python"
}
}
}
4. Configure Node.js Application
Create a Node.js app (server.js):
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from Node.js on Nginx Unit!');
});
server.listen(8082);
Create a JSON configuration:
{
"applications": {
"nodejs": {
"type": "nodejs",
"processes": 2,
"working_directory": "/var/www/nodejs",
"script": "server.js"
}
},
"listeners": {
"127.0.0.1:8082": {
"pass": "applications/nodejs"
}
}
}
Testing and Verification
After configuration, load the config:
curl -X PUT --data-binary @/path/to/config.json http://localhost:8080/config
Test the services:
curl http://127.0.0.1:8080
curl http://127.0.0.1:8081
curl http://127.0.0.1:8082
If all return the correct output, the configuration is successful.
Solutions for AI and Self-Hosted LLMs
Nginx Unit’s multi-language support makes it ideal for AI systems such as:
- API Gateway for self-hosted LLM models
- AI backend applications for TTS, NLP, OCR
- Python and Node.js data analysis pipelines
Combined with high-RAM Cloud VPS, you can run multiple services simultaneously without resource constraints.
Alternative Solutions and Notes
In some cases, you may use Nginx + PHP-FPM, Gunicorn, or uWSGI. However, Nginx Unit simplifies configuration and reduces system complexity.
For AI workloads requiring heavy processing, ensure your VPS has sufficient RAM and CPU. Consider Dedicated Servers for AI and Inference Workloads if higher performance is needed.
References
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
