Host several applications behind one Nginx
27 Nov 2026 deployment nginx
Separate users, local ports and server blocks keep many small apps manageable.
One server can run several small applications if each keeps to its own space.
The pattern
- Each application runs as its own system user
- Each listens on its own port on
127.0.0.1 - Nginx is the only thing facing outwards
- Each has its own server block and log files
Route by name
server {
listen 20002;
server_name api.example.com;
location / { proxy_pass http://127.0.0.1:3001; }
}
server {
listen 20002;
server_name admin.example.com;
location / { proxy_pass http://127.0.0.1:3002; }
}
Names are matched on the same port, so one forwarded port can serve several sites on a shared address. On a dedicated address use 443.
Add a default that refuses
server {
listen 20002 default_server;
return 444;
}
Contain failures
Give each service a memory limit in its systemd unit so one leak does not take all of them down.
Share carefully
One database server is fine; give every application its own database and password.
When to split
Move an application to its own server when its risk, load or release schedule starts affecting the others.
See the reverse proxy article for full headers.